jfrasch / qpDUNES

qpDUNES - an implementation of the DUal NEwton Strategy for quadratic programming
24 stars 17 forks source link

A build error when running make.m in matlab interface #9

Open YeZhao opened 7 years ago

YeZhao commented 7 years ago

Hello, when I build qpDUNES in ./interfaces/matlab by running 'make.m', the following error shows up.

Building with 'Xcode Clang++'.
gcc -c -D__cpluplus  -D__MATLAB__  -DLINUX   -DMATLAB_MEX_FILE  -I. -I../../include -I../../externals/qpOASES-3.0beta/include -I../../interfaces/mpc  -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.12 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -O2 -DNDEBUG /Users/yezhao/Downloads/qpDUNES/interfaces/matlab/qpDUNES.cpp -o /var/folders/bk/p_h3ng_95dlfg8xpyg98n69h0000gn/T//mex_17967324059907_28912/qpDUNES.o
Error using mex
In file included from /Users/yezhao/Downloads/qpDUNES/interfaces/matlab/qpDUNES.cpp:39:
./qpDUNES_matlab_utils.cpp:436:24: error: non-constant-expression cannot be narrowed from type
'int' to 'mwSize' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
        mwSize dims[2] = { 1, numIter+1 };
                              ^~~~~~~~~
./qpDUNES_matlab_utils.cpp:436:24: note: insert an explicit cast to silence this issue
        mwSize dims[2] = { 1, numIter+1 };
                              ^~~~~~~~~
                              static_cast<mwSize>( )
1 error generated.

Error in make (line 77)
    eval( cmd );

Besides the non-constant-expression error, another error that I am trying to fix is the mex cmd error. My cmd is

mex -v CC="gcc" CXX="gcc" LD="gcc" COPTIMFLAGS="$COPTIMFLAGS -O3" -output qpDUNES -I. -I../../include -I../../externals/qpOASES-3.0beta/include -I../../interfaces/mpc -largeArrayDims -D__cpluplus -D__MATLAB__ -cxx -O -DLINUX CFLAGS='$CFLAGS -fPIC' qpDUNES.cpp ../../src/stage_qp_solver_clipping.c ../../src/stage_qp_solver_qpoases.cpp ../../src/qpdunes_utils.c ../../src/dual_qp.c ../../src/matrix_vector.c ../../src/setup_qp.c ../../interfaces/mpc/setup_mpc.c

Does anyone know the potential reason for this issue? Thank you. Build qpDUNES in its root directory works fine in my case (run make in terminal) and I can run the examples. I am using matlab R2015a in MacOS Sierra 10.12.1.

dkouzoup commented 7 years ago

Hey. I had recently problems making the matlab interface on Sierra, although I do not recall the exact error. Switching from clang to gcc fixed it for me. Careful though that you actually are indeed using gcc, since on mac, the gcc command is aliased to clang. Hope that helps!

YeZhao commented 7 years ago

Thanks for the reply, @dkouzoup. I think mex in the Matlab of Mac only uses Clang, though I can switch among different versions of Xcode (e.g., non-default version compiler). I also tried to switch the compiler with mex -setup C++ and the error still pops up. Hmm... I wonder whether it makes sense to ask for a precompiled version of qpDUNES, since I just want to test a few function calls from qpDUNES literally (i guess it highly depends on matlab and Mac OS version). Thanks.

YeZhao commented 7 years ago

I saw a similar error when running qpOASES. When I removed -D__MATLAB__ in CPPFLAGS, the bug is fixed! Now the mex file can be generated. So I manipulated with the flag settings in make.m of qpDUNES in similar ways, and still trying to check whether any flag adjustment could fix the issue above.

dkouzoup commented 7 years ago

Hey. Thanks for looking into this. It is actually possible to change the compiler in matlab. Type in the command window:

edit /Users/YOUR_USER/.matlab/R2015a/mex_C_maci64.xml

and change all instances of clang to gcc, i.e.:

CC="/usr/local/bin/gcc-6"

if you have gcc-6 installed. Same for mex_C++_maci64.xml of course. I could also send you my compiled code if that helps.