borglab / gtsam

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.
http://gtsam.org
Other
2.63k stars 769 forks source link

Matlab wrapper cannot be compiled on M1 Mac #1478

Closed bowei20222023 closed 1 year ago

bowei20222023 commented 1 year ago

My computer is Macbook Pro 16inch with M1 pro. I am trying to install with Matlab wrapper by using the following command: cmake -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON ..

Matlab R2022b is installed in my Mac.

Error shown: -- GTSAM Version: 4.3a0 -- GTSAM is a shared library due to BUILD_SHARED_LIBS is ON -- GTSAM_POSE3_EXPMAP=ON, enabling GTSAM_ROT3_EXPMAP as well -- Found Eigen version: 3.4.0 -- checking for thread-local storage - found -- Could NOT find MKL (missing: MKL_INCLUDE_DIR MKL_LIBRARIES) -- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) -- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) -- Could NOT find TBB (missing: TBB_INCLUDE_DIRS TBB_LIBRARIES tbb tbbmalloc) (Required is at least version "4.4") -- Building 3rdparty -- Could NOT find GeographicLib (missing: GeographicLib_LIBRARY_DIRS GeographicLib_LIBRARIES GeographicLib_INCLUDE_DIRS) -- Building base -- Building basis -- Building geometry -- Building inference -- Building symbolic -- Building discrete -- Building hybrid -- Building linear -- Building nonlinear -- Building sam -- Building sfm -- Building slam -- Building navigation -- GTSAM Version: 4.3.0 -- Install prefix: /usr/local -- Building GTSAM - as a SHARED library -- Building base_unstable -- Building geometry_unstable -- Building linear_unstable -- Building discrete_unstable -- Building dynamics_unstable -- Building nonlinear_unstable -- Building slam_unstable -- Building partition_unstable -- GTSAM_UNSTABLE Version: 4.3.0 -- Install prefix: /usr/local -- gtwrap Package config : /usr/local/lib/cmake/gtwrap -- gtwrap version : 1.0 -- gtwrap CMake path : /usr/local/lib/cmake/gtwrap -- gtwrap library path : /usr/local/lib/gtwrap -- gtwrap binary path : /usr/local/bin/gtwrap -- gtwrap header path : /usr/local/include/gtwrap CMake Error at /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY MEX_COMPILER) (found version "9.13") Call Stack (most recent call first): /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindMatlab.cmake:2038 (find_package_handle_standard_args) wrap/cmake/MatlabWrap.cmake:10 (find_package) wrap/cmake/MatlabWrap.cmake:67 (find_and_configure_matlab) matlab/CMakeLists.txt:85 (matlab_wrap)

Can you help me out? Thanks in advance

varunagrawal commented 1 year ago

Seems like Cmake can't find Matlab on your machine. Have you installed Matlab to some non-standard location?

bowei20222023 commented 1 year ago

No, it is a standard place under Applications folder. It can be found using ls /Applications/MATLAB_R2022b.app/bin

bowei20222023 commented 1 year ago

This is the results of ls

% ls /Applications/MATLAB_R2022b.app/bin activate_matlab.sh lcdata_utf8.xml mcc controllingProduct.json ldd mex crash_analyzer.cfg m3iregistry mexext deactivate_matlab.sh maci64 mw_mpiexec deploytool matlab mw_smpd icutzdata matlab-glselector.sh mwpython lcdata.xml matlab_jenv util lcdata.xsd mbuild worker

mikesheffler commented 1 year ago

I'm not sure what's going on here, but a couple things that might be worth thinking about:

1) R2022b is fairly new. Is your CMake install up to date? I'm looking at the line

CMake Error at /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230

and wondering if FindPackage (or whatever it's dispatching) knows how to look for your version of MATLAB.

2) Maybe MATLAB can't match up the (MATLAB) library resources for your compiler? On Windows, there's a path similar to

C:\Program Files\MATLAB\R2022a\bin\win64\mexopts

that contains .xml files for all of the compilers that version of MATLAB knows how to work with, Sometimes when a newer compiler is used with an older version of MATLAB, that older version of MATLAB doesn't know how to coordinate with the newer compiler (imagine MATLAB 2018a and Visual Studio 2022 -- that version of Visual Studio didn't exist when that version of MATLAB shipped).

Anyway, I don't have any great ideas, but your MATLAB might indeed be installed in a 'normal' place and the build system doesn't think it can find it because an issue with CMake, MATLAB, or the compiler knowing about one another.

Good luck.

bowei20222023 commented 1 year ago

I updated Cmake and the error now is

CMake Error at matlab/CMakeLists.txt:46 (message): GTSAM_INSTALL_MATLAB_TOOLBOX and BUILD_SHARED_LIBS=OFF.The MATLAB wrapper cannot be compiled with a static GTSAM library because mex modules are themselves shared libraries.If you want a self-contained mex module, enable GTSAM_MEX_BUILD_STATIC_MODULE instead of BUILD_SHARED_LIBS=OFF.

I tried $ cmake -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON -DGTSAM_MEX_BUILD_STATIC_MODULE=ON .. and $ cmake -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON ..

the errors are the same.

bowei20222023 commented 1 year ago

I tried to install an early version of Matlab 2018b. But the issues exist:

They either give me the error like

CMake Error at /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Matlab (missing: Matlab_MEX_LIBRARY Matlab_MX_LIBRARY MEX_COMPILER) (found version "9.13") Call Stack (most recent call first): /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /opt/homebrew/Cellar/cmake/3.25.2/share/cmake/Modules/FindMatlab.cmake:2038 (find_package_handle_standard_args) wrap/cmake/MatlabWrap.cmake:10 (find_package) wrap/cmake/MatlabWrap.cmake:67 (find_and_configure_matlab) matlab/CMakeLists.txt:85 (matlab_wrap)

or CMake Error at matlab/CMakeLists.txt:46 (message): GTSAM_INSTALL_MATLAB_TOOLBOX and BUILD_SHARED_LIBS=OFF.The MATLAB wrapper cannot be compiled with a static GTSAM library because mex modules are themselves shared libraries.If you want a self-contained mex module, enable GTSAM_MEX_BUILD_STATIC_MODULE instead of BUILD_SHARED_LIBS=OFF.

mikesheffler commented 1 year ago

This error:

CMake Error at matlab/CMakeLists.txt:46 (message):
GTSAM_INSTALL_MATLAB_TOOLBOX and BUILD_SHARED_LIBS=OFF.The MATLAB wrapper
cannot be compiled with a static GTSAM library because mex modules are
themselves shared libraries.If you want a self-contained mex module, enable
GTSAM_MEX_BUILD_STATIC_MODULE instead of BUILD_SHARED_LIBS=OFF.

is from GTSAM (you can tell that from the relative path matlab/CMakeLists.txt:46).

The wording could probably be clearer, but what it is trying to tell you is that compiling GTSAM as a static library (something with a .a suffix that includes symbols for many of the libraries on which it relies) is not compatible with building the MATLAB toolbox.

If you are just trying to use GTSAM via the MATLAB toolbox, you'll need to compile GTSAM as a shared library (one with a .dylib suffix), and to do that you're going to need -DBUILD_SHARED_LIBS=ON as one of your cmake arguments (I thought that was the default option, but I'm not 100% sure).

You may need other options, but the cmake flags might look (in part) something like this:

$ cmake -DBUILD_SHARED_LIBS=ON -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON ..

You should not need to specify a value for -DGTSAM_MEX_BUILD_STATIC_MODULE, and if you were to supply one, it should be OFF.

Try building things that way first. If it works, and you really do need static libraries (either GTSAM or something MATLAB-related), you can work up to that problem later.

mattking-smith commented 1 year ago

Is this a MATLAB 2022 issue somehow?

A similar MATLAB toolbox enable problem looks like it has popped up on a Unix OS on issue #1476

varunagrawal commented 1 year ago

This is definitely a Mac issue. I unfortunately don't have cycles to debug but it's definitely a path related issue.

varunagrawal commented 1 year ago

I have an update on this. For Matlab 2022, you need to use CMake 2.26 and above. It comes with improved support for finding the necessary mex binaries especially on Apple silicon. As for the the shared library issue, @mikesheffler has done a wonderful job answering your question. @bowei20222023 can you please try these out and let us know if it works for you?

bowei20222023 commented 1 year ago

Thanks, Varun. It works by using $ cmake -DBUILD_SHARED_LIBS=ON -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON .. Just one minor correction, it should be CMake 2.36? I installed from brew. But another error happened to the very last step when doing "make install " please see the following? Should I open another thread?

[100%] Linking CXX shared module ../wrap/gtsam_mex/gtsam_wrapper.mexmaci64 ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmex.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64 ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64 ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmat.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64 Undefined symbols for architecture arm64: "_mexAtExit", referenced from: gtsamKeyList_collectorInsertAndMakeBase_0(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeyList_constructor_1(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeyList_constructor_2(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_collectorInsertAndMakeBase_17(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_18(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_19(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_20(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mexCallMATLABWithObject", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o "_mexErrMsgIdAndTxt", referenced from: error(char const) in gtsam_wrapper.cpp.o checkScalar(mxArray_tag const, char const) in gtsam_wrapper.cpp.o checkArguments(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, int, int, int) in gtsam_wrapper.cpp.o std::1::basic_string<char, std::__1::char_traits, std::1::allocator > unwrap<std::1::basic_string<char, std::__1::char_traits, std::1::allocator > >(mxArray_tag const) in gtsam_wrapper.cpp.o bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mexErrMsgTxt", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o _mexFunction in gtsam_wrapper.cpp.o "_mexGetVariablePtr", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mexGetVariableWithObject", referenced from: _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mexPrintf", referenced from: mstream::xsputn(char const, long) in gtsam_wrapper.cpp.o mstream::overflow(int) in gtsam_wrapper.cpp.o "_mexPutVariable", referenced from: _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mxAddField", referenced from: _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mxArrayToString", referenced from: std::1::basic_string<char, std::__1::char_traits, std::1::allocator > unwrap<std::1::basic_string<char, std::__1::char_traits, std::1::allocator > >(mxArray_tag const) in gtsam_wrapper.cpp.o "_mxCreateDoubleMatrix_700", referenced from: wrap_Vector(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(Eigen::Matrix<double, 2, 1, 0, 2, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&) in gtsam_wrapper.cpp.o wrap_Matrix(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&) in gtsam_wrapper.cpp.o extractPoint2_84(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxCreateDoubleScalar", referenced from: mxArray_tag wrap(double const&) in gtsam_wrapper.cpp.o gtsamChebyshev2_Point_224(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamChebyshev2_Point_225(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamDotWriter_get_figureWidthInches_533(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamDotWriter_get_figureHeightInches_535(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamDiscreteConditional_error_640(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamDiscreteConditional_error_641(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxCreateNumericArray_700", referenced from: scalar(mxClassID) in gtsam_wrapper.cpp.o mxArray_tag wrap(char const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(unsigned char const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(bool const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(unsigned long const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(int const&) in gtsam_wrapper.cpp.o gtsamKeyList_back_4(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxCreateNumericMatrix_700", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o gtsamKeyList_constructor_1(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeyList_constructor_2(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_18(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_19(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_constructor_20(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxCreateString", referenced from: mxArray_tag wrap<std::1::basic_string<char, std::__1::char_traits, std::1::allocator > >(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o gtsamKeyList_string_serialize_13(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeySet_string_serialize_32(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamKeyVector_string_serialize_45(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o gtsamRedirectCout_str_106(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxCreateStructMatrix_700", referenced from: _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mxDestroyArray", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o "_mxFree", referenced from: std::1::basic_string<char, std::__1::char_traits, std::1::allocator > unwrap<std::1::basic_string<char, std::__1::char_traits, std::1::allocator > >(mxArray_tag const) in gtsam_wrapper.cpp.o "_mxGetClassID", referenced from: bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o int unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned long unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o double unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o std::__1::shared_ptr<gtsam::FastList > unwrap_shared_ptr<gtsam::FastList >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o ... "_mxGetData", referenced from: mxArray_tag wrap(char const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(unsigned char const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(bool const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(unsigned long const&) in gtsam_wrapper.cpp.o mxArray_tag wrap(int const&) in gtsam_wrapper.cpp.o bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxGetField_700", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o "_mxGetM", referenced from: checkScalar(mxArray_tag const, char const) in gtsam_wrapper.cpp.o bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o int unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned long unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o double unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxGetN", referenced from: checkScalar(mxArray_tag const, char const) in gtsam_wrapper.cpp.o bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o int unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned long unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o double unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxGetPr", referenced from: wrap_Vector(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(Eigen::Matrix<double, 2, 1, 0, 2, 1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&) in gtsam_wrapper.cpp.o wrap_Matrix(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&) in gtsam_wrapper.cpp.o mxArray_tag wrap<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&) in gtsam_wrapper.cpp.o extractPoint2_84(int, mxArray_tag, int, mxArray_tag const) in gtsam_wrapper.cpp.o ... "_mxGetProperty_700", referenced from: std::__1::shared_ptr<gtsam::FastList > unwrap_shared_ptr<gtsam::FastList >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr<gtsam::FastSet > unwrap_shared_ptr<gtsam::FastSet >(mxArray_tag const*, std::1::basic_string<char, std::1::char_traits, std::__1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr<std::1::vector<unsigned long long, std::1::allocator > > unwrap_shared_ptr<std::1::vector<unsigned long long, std::1::allocator > >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::__1::shared_ptr<gtsam::FastMap<unsigned long long, int> > unwrap_shared_ptr<gtsam::FastMap<unsigned long long, int> >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr unwrap_shared_ptr(mxArray_tag const*, std::1::basic_string<char, std::1::char_traits, std::__1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr<gtsam::PinholeCamera > unwrap_shared_ptr<gtsam::PinholeCamera >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::__1::shared_ptr unwrap_shared_ptr(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o ... "_mxGetScalar", referenced from: bool unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned char unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o int unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o unsigned long unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o double unwrap(mxArray_tag const) in gtsam_wrapper.cpp.o "_mxGetString_700", referenced from: create_object(std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&, void, bool, char const) in gtsam_wrapper.cpp.o "_mxIsComplex", referenced from: std::1::shared_ptr<gtsam::FastList > unwrap_shared_ptr<gtsam::FastList >(mxArray_tag const*, std::1::basic_string<char, std::1::char_traits, std::__1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr<gtsam::FastSet > unwrap_shared_ptr<gtsam::FastSet >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::__1::shared_ptr<std::1::vector<unsigned long long, std::1::allocator > > unwrap_shared_ptr<std::1::vector<unsigned long long, std::1::allocator > >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr<gtsam::FastMap<unsigned long long, int> > unwrap_shared_ptr<gtsam::FastMap<unsigned long long, int> >(mxArray_tag const*, std::1::basic_string<char, std::1::char_traits, std::__1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr unwrap_shared_ptr(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::__1::shared_ptr<gtsam::PinholeCamera > unwrap_shared_ptr<gtsam::PinholeCamera >(mxArray_tag const, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) in gtsam_wrapper.cpp.o std::1::shared_ptr unwrap_shared_ptr(mxArray_tag const*, std::1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) in gtsam_wrapper.cpp.o ... "_mxIsDouble", referenced from: Eigen::Matrix<double, -1, 1, 0, -1, 1> unwrap<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(mxArray_tag const) in gtsam_wrapper.cpp.o Eigen::Matrix<double, 2, 1, 0, 2, 1> unwrap<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(mxArray_tag const) in gtsam_wrapper.cpp.o Eigen::Matrix<double, 3, 1, 0, 3, 1> unwrap<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(mxArray_tag const) in gtsam_wrapper.cpp.o Eigen::Matrix<double, -1, -1, 0, -1, -1> unwrap<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(mxArray_tag const) in gtsam_wrapper.cpp.o "_mxSetFieldByNumber_700", referenced from: _gtsam_RTTIRegister() in gtsam_wrapper.cpp.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: [wrap/gtsam_mex/gtsam_wrapper.mexmaci64] Error 1 make[1]: [matlab/CMakeFiles/gtsam_matlab_wrapper.dir/all] Error 2 make: *** [all] Error 2

mikesheffler commented 1 year ago

But another error happened to the very last step when doing "make install " ... please see the following? ... Should I open another thread?

Not yet -- I think this still makes sense as part of the issue we have been discussing.

This part:

[100%] Linking CXX shared module ../wrap/gtsam_mex/gtsam_wrapper.mexmaci64
ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmex.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmat.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_mexAtExit", referenced from:
gtsamKeyList_collectorInsertAndMakeBase_0(int, mxArray_tag**, int, mxArray_tag const**) in gtsam_wrapper.cpp.o

...

is telling you that there is a linker error (Undefined symbols ...). The object file it is putting together when the error occurs is gtsam_wrapper.cpp.o. Specifically, the function gtsamKeyList_collectorInsertAndMakeBase_0 calls the function _mexAtExist, and the linker does not have symbols for that function (_mexAtExist). In particular, ld does not have symbols in the arm64 architecture for function _mexAtExist.

Before that error is emitted, we can see a warning from the linker:

ld: warning: ignoring file /Applications/MATLAB_R2022b.app/bin/maci64/libmex.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

that it (ld) has ignored (among others) the file libmex.dylib because libmex.dylib has symbols for the macOS-x86_64 architecture (that's the architecture for Intel-based Macs), but ld is currently linking for a shared module (gtsam_wrapper.mexmaci64) that has architecture macOS-arm64 (the Apple M1 Silicon-based Macs).

It looks like there are a few problems that are repeats of the same underlying issue. Even though it's just a warning, it's almost definitely what is wrong, but I'm not 100% sure what is right.

1) If you have an M1 Mac and are building GTSAM 'natively' as an M1 shared library, then CMake probably has to be convinced to look for the M1-based MATLAB shared libraries that are used in mex functions.

Hopefully, that helps.

bowei20222023 commented 1 year ago

Mine is M1 pro Macbook.

If you have an M1 Mac and are building GTSAM 'natively' as an M1 shared library, then CMake probably has to be convinced to look for the M1-based MATLAB shared libraries that are used in mex functions. If you don't have an M1-based version of MATLAB, I don't think this will work.

The solution you suggest would be to install M1-based MATLAB. https://uk.mathworks.com/support/apple-silicon-r2022b-beta.html

I am a little hesitant, as it is a beta version. I tried to install two Matlabs, but it turned it messed up the whole environment. The terminal could not find the correct Matlab.

varunagrawal commented 1 year ago

Yeah this has to do with lack of support on our end for Apple chips. We need to make some CMake updates to get this to work. I'll have to double check though since it seems that I am not using the M1-based Matlab either, so it could be a combination of the 2.

varunagrawal commented 1 year ago

Adding an update: the Cmake fix for this is straightforward. Unfortunately an M1 supported version of Matlab is required to successfully link against and the version from Mathworks is still in Beta. :(

I'll make the PR later today, but that's the extent of how much we can control. The only thing to do is wait for the good people at Mathworks to make an arm64 compatible release.