osqp-eigen icon indicating copy to clipboard operation
osqp-eigen copied to clipboard

Cant instantiate the solver; "OsqpEigen::Solver solver"

Open dhruvthanki opened this issue 4 years ago • 8 comments

This is how I build the wrapper: (I am using windows btw)

git clone https://github.com/robotology/osqp-eigen.git
cd osqp-eigen
mkdir build && cd build
cmake ../
cmake --build . --config Debug

This is my CmakeLists.txt file:

cmake_minimum_required(VERSION "3.20.0")

project("-----")

find_package (Eigen3 3.3 REQUIRED NO_MODULE)
find_package(osqp REQUIRED)
find_package(OsqpEigen REQUIRED PATHS "C:/Users/Dhruv/Documents/GitHub/osqp-eigen/build")

include_directories("C:/Users/Dhruv/Documents/mujoco200_win64/include")
link_directories("C:/Users/Dhruv/Documents/mujoco200_win64/bin")

add_executable("${PROJECT_NAME}" "main.cpp")

target_link_libraries("${PROJECT_NAME}" 
mujoco200
mujoco200nogl
glfw3
glfw3static
Eigen3::Eigen
osqp::osqpstatic
# osqp::osqp
OsqpEigen::OsqpEigen)

osqp-sol

I am able to compile and run the "osqp" example problems from their website. I am able to include the OsqpEigen.h in my project. When I just instantiate the solver using the wrapper, I am able to build and run the .exe but no output that I was expecting is generated. Just builds and runs with zero errors and nothing happens.

#include <iostream>
#include <Eigen/Core>
#include "osqp.h"
#include "OsqpEigen/OsqpEigen.h"

int main(void){
    std::cout << "Hello1" << std::endl;

    // instantiate the solver
    OsqpEigen::Solver solver;
 
    std::cout << "Hello2" << std::endl;

    return 1;
}

dhruvthanki avatar Apr 24 '21 17:04 dhruvthanki

Hi @dhruvthanki, thanks for the issue. Just to understand, what does your program print? The Solver object does not print anything and it is supposed to do nothing until you set the problem and call the solve method.

S-Dafarra avatar Apr 24 '21 18:04 S-Dafarra

So if I just compile and run the above code, should it print the following in the terminal or not?

Hello1
Hello2

dhruvthanki avatar Apr 24 '21 18:04 dhruvthanki

So if I just compile and run the above code, should it print the following in the terminal or not?

Hello1
Hello2

I think so! Does it get stuck before?

S-Dafarra avatar Apr 24 '21 18:04 S-Dafarra

If I run it without instantiating the solver in the main, I get the first output. If I run it with the instantiation, I get the second output: 111111

dhruvthanki avatar Apr 24 '21 18:04 dhruvthanki

Ok, that seems to be crashing then. I wonder if that is because you are linking also osqpstatic. OsqpEigen is already linking osqp. Can you try to not link to osqpStatic?

If that is not the case, can you try to launch the tests of OsqpEigen?

S-Dafarra avatar Apr 24 '21 19:04 S-Dafarra

I build the MPCExample and launched the MPCExample.exe. No changes to the CmakeLists.txt that was in the example dir. No Error while building, no error while running. The display output option is turned on.

solver.settings()->setVerbosity(true);

2222222

dhruvthanki avatar Apr 24 '21 20:04 dhruvthanki

Can you try to avoid linking the osqp::osqpstatic target? As @S-Dafarra mentioned, OsqpEigen::OsqpEigen already links the shared target osqp::osqp, and mixing the two can create strange behaviors.

traversaro avatar Apr 25 '21 20:04 traversaro

If also the example crashes, I think that OsqpEigen did not compile correctly. Can you list the commands you used to compile osqp and OsqpEigen, as suggested in https://github.com/robotology/osqp-eigen/issues/77#issuecomment-826065428?

Probably it would be better to start with some clean builds.

Also, make sure you don't have any other osqp installations on your system. Some projects, like acados, are used to ship a version of osqp that is not compatible with OsqpEigen (see https://github.com/robotology/osqp-eigen/issues/81 for example).

S-Dafarra avatar Apr 26 '21 07:04 S-Dafarra