How to determine which libraries to include when using Matlab C++ API?
4 ビュー (過去 30 日間)
古いコメントを表示
Given the example file matcreat.cpp on linux with GCC and Matlab installed correctly. I can link with
.... -L<matlab_root>/bin/glnxa64/ -Wl, -rpath,<matlab_root>/bin/glnxa64/ .... -lmx -lmex -lmat -lm
The resulting executable will work as intended. However, how do I know that I chose the correct libraries? If I remove all but -lmat I will receive "undefined reference to symbol 'mxCreateDoubleMatrix@@v7.3'. This appears to be something in the mxArray set of functions so I added -lmx and all the errors are resolved. The code compiles correctly and the output is as expected. I assume from this that -lmex -lm are extra and not needed, or found by the linker per normal processing. If I compile this same code with no libraries I get the following.
...: undefined reference to `mxCreateDoubleMatrix'
...: undefined reference to `mxGetPr'
...: undefined reference to `mxCreateDoubleMatrix'
...: undefined reference to `mxGetPr'
...: undefined reference to `mxCreateString'
...: undefined reference to `matOpen'
...: undefined reference to `matPutVariable'
...: undefined reference to `matPutVariable'
...: undefined reference to `matPutVariable'
...: undefined reference to `mxDestroyArray'
...: undefined reference to `mxDestroyArray'
...: undefined reference to `mxDestroyArray'
...: undefined reference to `matClose'
My question is what is the documentation or reference to tell me that I need to link against -lmat and -lmx for my code? And by extension which libraries to use for other features like the engine.
1 件のコメント
Siddharth Bhutiya
2019 年 1 月 8 日
Below are some documentations link that could help identify what API uses which libraries and accordingly you can use the corresponding flag.
Also you could take a look at the answers post below
Here, it uses the "--as-needed" flag to link only the libraries that are used
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call MATLAB from C++ についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!