Closed LoreMoretti closed 3 months ago
Now, I will try to generate the Matlab bindings following generating-idyntree-matlab-bindings.md
Now, I will try to generate the Matlab bindings following generating-idyntree-matlab-bindings.md
I am getting the following error when running make
:
[ 99%] Built target iDynTreeMEX_swig_compilation
[ 99%] Building CXX object bindings/matlab/CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o
/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/bindings/matlab/autogenerated/iDynTreeMATLAB_wrap.cxx:171:10: fatal error: mex.h: No such file or directory
171 | #include <mex.h>
| ^~~~~~~
compilation terminated.
make[2]: *** [bindings/matlab/CMakeFiles/iDynTreeMEX.dir/build.make:76: bindings/matlab/CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:954: bindings/matlab/CMakeFiles/iDynTreeMEX.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Do you have MATLAB installed in the system? What is the CMakeCache.txt
of your build?
Do you have MATLAB installed in the system? What is the
CMakeCache.txt
of your build?
Yes, here the CMakeCache.txt
Ok, somehow is not finding the mex.h
file, not sure why. I think we can:
mex.h
file is indeed there, for example with find /usr/local/MATLAB/R2023b/extern/include | grep mex.h
iDynTreeMATLAB_wrap.cxx
, to get the exact command used to compile iDynTreeMATLAB_wrap.cxx
, you can either compile with make VERBOSE=1
or ninja -vv
, or simply search for iDynTreeMATLAB_wrap.cxx
in your compile_command.json . You should find a -I<path>
or -Isystem<path>
option that points to the folder that contains the mex.h
file. The mex.h
file exists:
(robsub) lomoretti@IITICUBLAP226:~/robotology/robotology-superbuild/build/src/iDynTree (master)$ find /usr/local/MATLAB/R2023b/extern/include | grep mex.h
/usr/local/MATLAB/R2023b/extern/include/mex.h
Then I tried with make VERBOSE=1
as you suggested. I am reporting just the chunk related to the error:
[ 99%] Building CXX object bindings/matlab/CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o
cd /home/lomoretti/robotology/robotology-superbuild/build/src/iDynTree/bindings/matlab && /home/lomoretti/mambaforge/envs/robsub/bin/x86_64-conda-linux-gnu-c++ -DiDynTreeMEX_EXPORTS -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/core/include -I/home/lomoretti/robotology/robotology-superbuild/build/src/iDynTree/src/core -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/model/include -I/home/lomoretti/robotology/robotology-superbuild/build/src/iDynTree/src/model -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/model_io/xml/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/model_io/xml/include/iDynTree -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/model_io/codecs/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/model_io/codecs/include/private -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/estimation/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/solid-shapes/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/high-level/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/inverse-kinematics/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/optimalcontrol/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/yarp/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/icub/include -I/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/src/visualization/include -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/lomoretti/mambaforge/envs/robsub/include -g -fPIC -Wno-deprecated-declarations -Wno-deprecated -MD -MT bindings/matlab/CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o -MF CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o.d -o CMakeFiles/iDynTreeMEX.dir/autogenerated/iDynTreeMATLAB_wrap.cxx.o -c /home/lomoretti/robotology/robotology-superbuild/src/iDynTree/bindings/matlab/autogenerated/iDynTreeMATLAB_wrap.cxx
/home/lomoretti/robotology/robotology-superbuild/src/iDynTree/bindings/matlab/autogenerated/iDynTreeMATLAB_wrap.cxx:171:10: fatal error: mex.h: No such file or directory
171 | #include <mex.h>
And indeed there is not the /usr/local/MATLAB/R2023b/extern/include/
among the directories.
And indeed there is not the
/usr/local/MATLAB/R2023b/extern/include/
among the directories.
That is interesting, by looking into https://github.com/robotology/idyntree/blob/d6af7ff4aa46bd8a4e3cfa8e8abc316908dbd4fd/bindings/matlab/CMakeLists.txt#L118 I could not understand which command should actually ensure that is the case. Probably it is a bug of the combination of trying to generate+compile the source code in the same step, while typically we (and the CI) generate the source code in one build, and compile in another.
Can you try to add:
target_include_directories(${target_name} PRIVATE ${Matlab_INCLUDE_DIRS})
right before https://github.com/robotology/idyntree/blob/d6af7ff4aa46bd8a4e3cfa8e8abc316908dbd4fd/bindings/matlab/CMakeLists.txt#L118 ?
Thanks! Note that in general this is not required as setting the include directories is handled by passing to target_link_libraries
the correct imported targets, however to be compatible with CMake 3.16 we can't use the imported targets Matlab::mex
and Matlab::mx
, there are available since CMake 3.22 (see https://cmake.org/cmake/help/v3.29/module/FindMatlab.html#imported-targets).
Awesome, it worked!
I have included the line target_include_directories(${target_name} PRIVATE ${Matlab_INCLUDE_DIRS})
in this PR.
Thanks @LoreMoretti !
This PR addresses #1082.