필터 지우기
필터 지우기

How to solve mex function error caused by libstdc++ library version mismatch ?

조회 수: 17 (최근 30일)
Matt
Matt 2024년 5월 24일
댓글: Matt 2024년 5월 31일
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")

채택된 답변

Poorna
Poorna 2024년 5월 29일
Hi Matt,
I see you are facing errors while trying to compile using the "mex" function. I see you also have found a solution to the problem which is to set the environment variable LD_PRELOAD to the right libstdc++. More information on this can be found in the below documentation: https://www.mathworks.com/help/compiler/mcr-path-settings-for-run-time-deployment.html
The above documentation also provides you a way to set the env variable permanently by appending the command to the ~./bashprofile. This will set the env variable to all applications which might not be desirable.
You could on the other hand try leveraging the startup.m file to set the env variable. This will automate the process so that you need not use the entire "LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6 matlab" command. "setenv" function can be used to set the env variable.
Refer to the following documentation to know about "startup.m" file and "setenv" function:
You can find an example usage of the "startup" file to set env variable in the below MATLAB Answer:
Hope this Helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by