coin-or / qpOASES

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

Python interface erro when compiling #128

Open dignakov opened 2 years ago

dignakov commented 2 years ago

Hi,

I'm trying to test the Python interface, but I'm running into a couple of issues (Ubuntu 20.04)

(1) when building with CMake 'libqpOASES' is placed in the libs directory, but the python installation process is looking for it in the bin directory:

$ python3 setup.py build_ext --inplace
.
.
.
x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/qpoases.o -L/home/dmitri/code/qpOASES_orig/bin -Wl,--enable-new-dtags,-R/home/dmitri/code/qpOASES_orig/bin -lqpOASES -o /home/dmitri/code/qpOASES_orig/interfaces/python/qpoases.cpython-38-x86_64-linux-gnu.so -Wl,-O1 -Wl,--as-needed
/usr/bin/ld: cannot find -lqpOASES
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1

(2) If I manually move the lib, I still get an error about relocation R_X86_64_PC32 against symbol '_ZTTN7qpOASES11SymDenseMatE' can not be used when making a shared object; recompile with -fPIC

$ python3 setup.py build_ext --inplace
.
.
.
x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/qpoases.o -L/home/dmitri/code/qpOASES_orig/bin -Wl,--enable-new-dtags,-R/home/dmitri/code/qpOASES_orig/bin -lqpOASES -o /home/dmitri/code/qpOASES_orig/interfaces/python/qpoases.cpython-38-x86_64-linux-gnu.so -Wl,-O1 -Wl,--as-needed
/usr/bin/ld: /home/dmitri/code/qpOASES_orig/bin/libqpOASES.a(QProblemB.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTTN7qpOASES11SymDenseMatE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1

One more update . . . (I installed everything into a virtualenv, so the library is in the right place, and ld is able to find the .so)

I also tried building the library with -DBUILD_SHARED_LIBS=ON, then installing it system wide.

At this point the python interface compiles, but I get this:

/tmp/ipykernel_3558/584781938.py in <module>
      1 import numpy as np
----> 2 from qpoases import PyQProblem as QProblem
      3 from qpoases import PyOptions as Options
      4 from qpoases import PyPrintLevel as PrintLevel

ImportError: /home/dmitri/.virtualenvs/env_vscode/lib/python3.8/site-packages/qpoases.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN7qpOASES8QProblem4initEPKdS2_S2_S2_S2_S2_S2_RlPdS2_S2_PKNS_6BoundsEPKNS_11ConstraintsES2_