robotology / osqp-eigen

Simple Eigen-C++ wrapper for OSQP library
https://robotology.github.io/osqp-eigen/
BSD 3-Clause "New" or "Revised" License
381 stars 112 forks source link

trouble building the library #155

Closed baharehhj closed 6 months ago

baharehhj commented 6 months ago

I'm encountering challenges while building and installing the library in my C++ environment. My objective is to implement a quadratic programming function similar to MATLAB's quadprog() function with inputs which are sparse matrix. However, I'm facing difficulties defining addresses for Eigen, OSQP (compiled with 64-bit integers) during the build process.

After cloning the library, I added a build folder and ran cmake .. in the command line, which resulted in a successful build:

C:\osqp\osqp-Eigen\build>cmake ..

 -- Building for: Visual Studio 17 2022
    -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
    -- The C compiler identification is MSVC 19.37.32822.0
    -- The CXX compiler identification is MSVC 19.37.32822.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done (9.9s)
    -- Generating done (0.1s)
    -- Build files have been written to: C:/osqp/osqp-Eigen/build

However, when I opened OSqp-eigen.sln in Visual Studio and attempted to build it, I encountered the following errors:

 Build started...
    1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
    1>1>Checking Build System
    2>------ Build started: Project: OsqpEigen, Configuration: Debug x64 ------
    2>Building Custom Rule C:/osqp/osqp-Eigen/CMakeLists.txt
    2>Data.cpp
    2>Settings.cpp
    2>Solver.cpp
    2>Debug.cpp
    2>Generating Code...
    2>Auto build dll exports
    2>   Creating library C:/osqp/osqp-Eigen/build/Debug/OsqpEigend.lib and object C:/osqp/osqp-Eigen/build/Debug/OsqpEigend.exp
    2>Data.obj : error LNK2019: unresolved external symbol csc_spfree referenced in function "public: void __cdecl OsqpEigen::Data::clearHessianMatrix(void)" (?clearHessianMatrix@Data@OsqpEigen@@QEAAXXZ)
    2>Solver.obj : error LNK2019: unresolved external symbol csc_spalloc referenced in function "bool __cdecl OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix<class Eigen::SparseMatrix<double,0,int> >(class Eigen::SparseCompressedBase<class Eigen::SparseMatrix<double,0,int> > const &,struct OSQPCscMatrix * &)" (??$createOsqpSparseMatrix@V?$SparseMatrix@N$0A@H@Eigen@@@SparseMatrixHelper@OsqpEigen@@YA_NAEBV?$SparseCompressedBase@V?$SparseMatrix@N$0A@H@Eigen@@@Eigen@@AEAPEAUOSQPCscMatrix@@@Z)
    2>C:\osqp\osqp-Eigen\build\Debug\OsqpEigend.dll : fatal error LNK1120: 2 unresolved externals
    2>Done building project "OsqpEigen.vcxproj" -- FAILED.
    3>------ Build started: Project: ALL_BUILD, Configuration: Debug x64 ------
    3>Building Custom Rule C:/osqp/osqp-Eigen/CMakeLists.txt
    ========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    ========== Build started at 10:49 ق.ظ and took 08.958 seconds ========== 

It seems like there's a problem with finding OSQP and Eigen. Could someone provide guidance or a step-by-step process on how to properly define the addresses for Eigen and OSQP when building the library in the CMakeLists.txt file? Or any other ideas to resolve these errors?

thanks in advance

traversaro commented 6 months ago

I think this is the same problem reported in https://github.com/robotology/osqp-eigen/issues/146 . In a nutshell, which version of osqp are you using? osqp-eigen is working fine with the latest release of osqp (0.6.3), while with the master branch there are still some problems such as the one discussed in https://github.com/robotology/osqp-eigen/issues/146 . There is anything preventing you to use osqp 0.6.3 ?

baharehhj commented 6 months ago

Thank you for your prompt response.

Actually, I'm not an expert, so I hope my question isn't too simplistic. Here are the steps I followed:

First, I ran git clone https://github.com/osqp/osqp.git. Then I executed cmake .. in the build folder and proceeded to open osqp.sln and build ALL_BUILD and INSTALL. After that, I ran git clone for osqp-eigen, and I repeated the same steps for osqp-eigen. However, when I right-clicked on ALL_BUILD and tried to build it, I encountered the following errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol csc_spfree referenced in function "public: __cdecl OsqpEigen::Data::~Data(void)" (??1Data@OsqpEigen@@QEAA@XZ)    OsqpEigen   C:\osqp\osqp-eigen\build\Data.obj   1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol csc_spalloc referenced in function "bool __cdecl OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix<class Eigen::SparseMatrix<double,0,int> >(class Eigen::SparseCompressedBase<class Eigen::SparseMatrix<double,0,int> > const &,struct OSQPCscMatrix * &)" (??$createOsqpSparseMatrix@V?$SparseMatrix@N$0A@H@Eigen@@@SparseMatrixHelper@OsqpEigen@@YA_NAEBV?$SparseCompressedBase@V?$SparseMatrix@N$0A@H@Eigen@@@Eigen@@AEAPEAUOSQPCscMatrix@@@Z)   OsqpEigen   C:\osqp\osqp-eigen\build\Solver.obj 1   
traversaro commented 6 months ago

If you just clone the default branch of repos, you can get a version of a library with the latest changes that still need to be released. To avoid this, after you clone the repo you can checkout a given tag that identifies a specific release. I suggest you do this for osqp.

traversaro commented 6 months ago

@baharehhj if this works, can you close the issue? As we already have https://github.com/robotology/osqp-eigen/issues/146 to deal with the specific problem.