Matlab Engine / Linux problem - Linker Errors...

5 次查看(过去 30 天)
Hi, I'm trying to compile a simple Matlab engine app, and am hitting some linker problems.
I'm trying to use the Engine in an Eclipse project, and am essentially trying to repeat what was done in this example... http://www.mindchasers.com/dev/matlabengine
I've configured as described in the above link, and it builds ok, but then hits linker problems, and I get the following error....
Building target: matlabEngine_demo
Invoking: GCC C Linker
gcc -L/usr/local/MATLAB/R2016b/bin/glnxa64 -Xlinker -rpath -Xlinker /usr/local/MATLAB/R2016b/bin/glnxa64 -o "matlabEngine_demo" ./src/matlabEngine_demo.o -leng -lmx
/usr/local/MATLAB/R2016b/bin/glnxa64/libut.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/usr/local/MATLAB/R2016b/bin/glnxa64/libmx.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
collect2: error: ld returned 1 exit status
make: *** [matlabEngine_demo] Error 1
Clearly I have a problem somewhere. Does anyone have any idea what is going on? (This is RHEL7, Matlab R2016b, Eclipse Oxygen CDT)
Cheers, Arwel

回答(1 个)

Dhruvesh Patel
Dhruvesh Patel 2017-3-20
As I understand, you are calling MATLAB engine in your C/C++ application and facing linker errors which are thrown while looking for functions which are used by libmx.so.
Looking at the symbols that are missing ('std::__throw_out_of_range_fmt(char const*, ...)' ) it seems that your application is linked to a wrong version of 'libstdc++'. My guess is that you are using gcc version lower than gcc 4.9.
Here I could say that linking your application with libstdc++.so.6.0.20 (or above) will fix the issue that you have mentioned. But that would not fix all the issue that you might face in the future while calling MATLAB in your C/C++ application.
The libmx.so and libut.so which ship with MATLAB R2016b are configured to be used with a particular version of gcc (gcc 4.9x to be precise). The gcc 4.9 comes with version 6.0.20 of libstdc++.so as stated in the documentation.
So, updating your gcc to version 4.9x would be the best way to avoid this as well as all other linker errors that you might get on your current setup with MATLAB R2016b.
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from C 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by