How to solve mex function error caused by libstdc++ library version mismatch ?
Show older comments
Hello,
When compiling a mex function, and running it right after, I get an error saying :
Invalid C++ MEX-file 'myfun':
/usr/local/MATLAB/R2023b/interprocess/bin/glnxa64/mex/../../../../sys/os/glnxa64/libstdc++.so.6:
version `GLIBCXX_3.4.29' not found (required by ...
I saw on this matlab post that the issue is that the libstdc++ version used during compilation is not the one that matlab has on its path during execution. And indeed, the version in "/lib/x86_64-linux-gnu" (i use gcc that links to this lib stdc++ ) and "usr/local/MATLAB/R2023b/sys/os/glnxa64" are not the same.
As explained on the post, launching matlab using LD_PRELOAD to force the use of the right libstdc++ works:
LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
But it does not seem very clean. Is there a way to indicate to matlab that it should alwlays at startup load the the version of libstd in /lib/x86_64-linux-gnu ? On the matlab post somebody says that I could simply delete the matlab libstd version, but I don't know enough about matlab to feel confortable deleting some libraires.
Matt
PS : how I compile the mex function
mex (header_path,lib_path,'-lsome_lib', ...
'-lgomp',"CXXFLAGS=$CXXFLAGS '-fopenmp'",...
'COPTIMFLAGS=-O2',...
"CXXFLAGS=$CXXFLAGS '-Wall'",...
"/path/myfun.cpp")
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!