coin-or / qpOASES

Open-source C++ implementation of the recently proposed online active set strategy
GNU Lesser General Public License v2.1
360 stars 121 forks source link

Segmentation fault (core dumped) when using qpOASES with matplotlib #110

Closed hallfjonas closed 3 years ago

hallfjonas commented 3 years ago

Hello,

I wanted to use matplotlib-cpp to create some plots after solving some QPs with qpOASES. I ran into a weird issue where I could not simultaneously run the plot command while having a class property of type QProblem. My minimal working example contains one TestClass and a main function to create a plot:

class TestClass { public: TestClass();

            qpOASES::QProblem qp;

};


- TestClass.cpp

include "TestClass.hpp"

include

TestClass::TestClass() { }


- matplotlibtest.cpp

include

include

int main(int argc, char *argv[]) { std::cout << "Entering Main...\n"; std::vector x; std::vector f;

for (int i = 0; i < 100; i++) {
    x.push_back(3.1*i/100.0);
    f.push_back(std::sin(x[i]));
}

std::cout << "Plot vectors created...\n";

matplotlibcpp::plot(x, f);

std::cout << "Plot created ...\n";

matplotlibcpp::show();
std::cout << "leaving main ...\n";

return 0;

}


- Compiling with debug flag

g++ -g -Wall -pedantic matplotlibtest.cpp TestClass.cpp -I/usr/local/qpOASES/include -I/usr/local/matplotlib-cpp -I. -I/usr/include/python3.6m -I/usr/local/qpOASES/include/qpOASES -lpython3.6m -lqpOASES


- Running a.out gives the output

Entering Main... Plot vectors created... Segmentation fault (core dumped)


- If I compile after commenting the property qpOASES::Qproblem qp in TestClass.hpp, I get a plot and this output

Entering Main... Plot vectors created... Plot created ... leaving main ...



The weird thing is that the TestClass is not even used in the main program, neither is the header file included in that main program. I simply compile it to potentially debug it once I use it...

Anybody have an idea what could be causing this behavior?

Cheers, Jonas
traversaro commented 3 years ago

I am not 100% sure this is the reason of your crash, but qpOASES redefines internally some BLAS/LAPACK functions, and this can create problems if linking with another library that uses BLAS or LAPACK. If you compiled qpOASES with CMake, you can try to use the PR https://github.com/coin-or/qpOASES/pull/108 and to set to ON the CMake option QPOASES_AVOID_LA_NAMING_CONFLICTS, and do your test again.

hallfjonas commented 3 years ago

I'm sorry it took me so long to verify this, but yes in fact this is the solution. Thank you so much!