robotology / osqp-eigen

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

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

Open dhruvthanki opened 3 years ago

dhruvthanki commented 3 years ago

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;
}
S-Dafarra commented 3 years ago

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.

dhruvthanki commented 3 years ago

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

Hello1
Hello2
S-Dafarra commented 3 years ago

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?

dhruvthanki commented 3 years ago

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

S-Dafarra commented 3 years ago

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?

dhruvthanki commented 3 years ago

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

traversaro commented 3 years ago

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.

S-Dafarra commented 3 years ago

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).