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

Installation issue with Python interface #120

Open jdiedrichsen opened 3 years ago

jdiedrichsen commented 3 years ago

On Python 3.7, Mac OSX 10.14, I run into the following problem when trying to install the Python interface, in each way outline in the README.rst file:

Any insight into the problem would be greatly appreciated.

Thanks!

Joern

(Python) bash-3.2$ make python cd ./interfaces/python/ && python setup.py build_ext --inplace Compiling qpoases.pyx because it depends on /Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/lib/python3.7/site-packages/numpy/init.pxd. [1/1] Cythonizing qpoases.pyx /Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /Users/jdiedrichsen/Python/qpOASES/interfaces/python/qpoases.pxd tree = Parsing.p_module(s, pxd, full_module_name) warning: qpoases.pyx:649:14: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables warning: qpoases.pyx:650:14: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables running build_ext building 'qpoases' extension creating build/temp.macosx-10.9-x86_64-3.7 gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/include -arch x86_64 -I/anaconda3/include -arch x86_64 -I/usr/include -I/Users/jdiedrichsen/Python/qpOASES/include -I/Users/jdiedrichsen/Python/qpOASES/include/qpOASES -I/Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/lib/python3.7/site-packages/numpy/core/include -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -I/Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/include -I/anaconda3/include/python3.7m -c qpoases.cpp -o build/temp.macosx-10.9-x86_64-3.7/qpoases.o -DUSE_LONG_INTEGERS -DUSE_LONG_FINTS -stdlib=libc++ -Wno-c++11-long-long -Wall -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -finline-functions -fPIC -DLINUX -DUSE_LONG_INTEGERS -DUSE_LONG_FINTS -D__NO_COPYRIGHT__ In file included from qpoases.cpp:71: /anaconda3/include/python3.7m/Python.h:14:2: error: "Something's broken. UCHAR_MAX should be defined in limits.h."

error "Something's broken. UCHAR_MAX should be defined in limits.h."

^ /anaconda3/include/python3.7m/Python.h:18:2: error: "Python's source code assumes C's unsigned char is an 8-bit type."

error "Python's source code assumes C's unsigned char is an 8-bit type."

^ /anaconda3/include/python3.7m/Python.h:27:5: error: "Python.h requires that stdio.h define NULL."

error "Python.h requires that stdio.h define NULL."

^

In file included from qpoases.cpp:71: In file included from /anaconda3/include/python3.7m/Python.h:30: /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:74:64: error: use of undeclared identifier 'strchr' char __libcpp_strchr(const char s, int c) {return (char)strchr(s, c);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:81:75: error: use of undeclared identifier 'strpbrk' char libcpp_strpbrk(const char __s1, const char s2) {return (char*)strpbrk(s1, s2);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:88:65: error: use of undeclared identifier 'strrchr'; did you mean 'strchr'? char* libcpp_strrchr(const char* s, int c) {return (char*)strrchr(s, c);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:76:13: note: 'strchr' declared here const char strchr(const char s, int c) {return libcpp_strchr(s, c);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:95:49: error: unknown type name 'size_t' void __libcpp_memchr(const void s, int c, size_t n) {return (void*)memchr(s, c, n);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:97:46: error: unknown type name 'size_t' const void memchr(const void s, int c, size_t n) {return libcpp_memchr(s, c, n);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:99:46: error: unknown type name 'size_t' void memchr( void s, int c, size_t n) {return libcpp_memchr(s, c, n);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:102:74: error: use of undeclared identifier 'strstr'; did you mean 'strchr'? char* libcpp_strstr(const char* s1, const char __s2) {return (char)strstr(s1, s2);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:78:13: note: 'strchr' declared here char strchr( char s, int c) {return libcpp_strchr(s, c);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:102:74: error: no matching function for call to 'strchr' char __libcpp_strstr(const char s1, const char __s2) {return (char)strstr(s1, s2);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:78:13: note: candidate disabled: char strchr( char s, int c) {return libcpp_strchr(s, c);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:102:81: error: cannot initialize a parameter of type 'char ' with an lvalue of type 'const char ' char __libcpp_strstr(const char s1, const char __s2) {return (char)strstr(s1, s2);} ^~~~ /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h:78:32: note: passing argument to parameter 's' here char strchr( char s, int c) {return libcpp_strchr(s, c);} ^ In file included from qpoases.cpp:71: In file included from /anaconda3/include/python3.7m/Python.h:34: /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:111:82: error: use of undeclared identifier 'labs'; did you mean 'abs'? inline _LIBCPP_INLINE_VISIBILITY long abs( long x) _NOEXCEPT {return labs(__x);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:111:44: note: 'abs' declared here inline _LIBCPP_INLINE_VISIBILITY long abs( long x) _NOEXCEPT {return labs(x);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:113:81: error: use of undeclared identifier 'llabs' inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(x);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:116:35: error: unknown type name 'ldiv_t' inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long x, long y) _NOEXCEPT {return ldiv(x, y);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:116:95: error: use of undeclared identifier 'ldiv'; did you mean 'div'? inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long x, long y) _NOEXCEPT {return ldiv(x, y);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:116:42: note: 'div' declared here inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long x, long y) _NOEXCEPT {return ldiv(x, y);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:118:34: error: unknown type name 'lldiv_t' inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long x, long long y) _NOEXCEPT {return lldiv(x, y);} ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:118:94: error: use of undeclared identifier 'lldiv' inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long x, long long y) _NOEXCEPT {return lldiv(x, y);} ^ In file included from qpoases.cpp:71: In file included from /anaconda3/include/python3.7m/Python.h:63: In file included from /anaconda3/include/python3.7m/pyport.h:191: /Library/Developer/CommandLineTools/usr/include/c++/v1/math.h:761:41: error: no member named 'fabsf' in the global namespace abs(float lcpp_x) _NOEXCEPT {return ::fabsf(lcpp_x);} ~~^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. error: command 'gcc' failed with exit status 1 make: *** [python] Error 1

apotschka commented 3 years ago

Doing cd ./interfaces/python/ && python setup.py build_ext --inplace works on my Mac (OSX 11.0.1, Anaconda 4.10.1, Python 3.8.2).

My suspicion is that your GCC does not find the correct header files. Maybe you have multiple GCC installations (some homebrew packages ship one, Anaconda Cython might have one, ...).

Please try the following (see stackoverflow and Cython Tutorial):

helloWorld.pyx:

print("Hello world")

setup.py:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloWorld.pyx")
)

Run on command line:

python setup.py build_ext --inplace

Does this compile?

jdiedrichsen commented 3 years ago

Hi - thanks for your answer. Yes- the basic cython helloworld compiles fine. I'm trying a clean reinstall of miniconda now to make sure, but not sure otherwise what is going on.

apotschka commented 3 years ago

Maybe this comparison of the gcc calls on our machines helps? I added spaces for better comparison.

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -arch x86_64 -I/usr/include -I/Users/potschka/git/qpOASES/include        -I/Users/potschka/git/qpOASES/include/qpOASES        -I/opt/anaconda3/lib/python3.8/site-packages/numpy/core/include                                               -I/Library/Developer/CommandLineTools/usr/include/c++/v1                                                                        -I/opt/anaconda3/include/python3.8 -c qpoases.cpp -o build/temp.macosx-10.9-x86_64-3.8/qpoases.o -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -stdlib=libc++ -Wno-c++11-long-long -Wall -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -finline-functions -fPIC -DLINUX -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -D__NO_COPYRIGHT__
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/include     -arch x86_64 -I/anaconda3/include     -arch x86_64 -I/usr/include -I/Users/jdiedrichsen/Python/qpOASES/include -I/Users/jdiedrichsen/Python/qpOASES/include/qpOASES -I/Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/lib/python3.7/site-packages/numpy/core/include -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -I/Users/jdiedrichsen/.local/share/virtualenvs/Python--3BEScb9/include -I/anaconda3/include/python3.7m    -c qpoases.cpp -o build/temp.macosx-10.9-x86_64-3.7/qpoases.o -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -stdlib=libc++ -Wno-c++11-long-long -Wall -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -finline-functions -fPIC -DLINUX -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -D__NO_COPYRIGHT__

The only differences I can spot is a different version of Python (3.7m vs. 3.8) and that you are using a virtual environment.

If you send me your commands for the creation of your virtual environment, I can try to replicate the issue on my MacBook.