How to manually select the libstdc++ library to use to resolve a "version 'GLIBCXX_#.#.##' not found" error?
이전 댓글 표시
I have generated a MEX file that links against a C++ compiled library. This MEX file was working correctly when running Ubuntu 20.04 and when I upgraded to Ubuntu 22.04, the same MEX file still worked. After making a change to the C wrapper code, I successfully rebuilt the MEX file with MATLAB R2022b. When trying to invoke the rebuilt MEX file, it failed due to the wrong GLIBCXX version with the following error:
Invalid MEX-file '.../decodeBitMatrix_mex.mexa64': /usr/local/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by .../decodeBitMatrix_mex.mexa64)
I see that the libstdc++ on my Ubuntu 22.04 system has two newer versions than what is shipped with MATLAB, as shown below:
$ strings /usr/local/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6 | grep GLIBCXX_3.4 | tail -4 GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
$ strings /lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX_3.4. | tail -4
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_3.4.30
How can I setup MATLAB or my system to use the same version of libstdc++?
채택된 답변
추가 답변 (1개)
Cris Luengo
2023년 11월 7일
편집: Cris Luengo
2023년 11월 7일
2 개 추천
The official solution to this (notwithstanding a MathWorks staff member suggesting LD_PRELOAD), is to install a version of GCC that is supported by your version of MATLAB. You can find them listed here for the latest MATLAB release, there's a button on the top-right to select an older version:
You have a newer version of GCC, hence a MEX-file compiled with it requires a newer version of the GCC libraries than the one that is loaded with MATLAB. Using the right GCC version ensures your MEX-file requires the same GCC libraries that come with MATLAB.
LD_PRELOAD is a workaround that forces MATLAB to run with the newer library, ignoring the one that it is distributed with. A simpler and more effective way of accomplishing the same thing is to simply delete the GCC libraries that come with MATLAB. They are in <matlabroot>/sys/os/glnxa64, and the files to delete are libstdc++.*, and possibly also the files libg2c.* and libgcc_s*.
카테고리
도움말 센터 및 File Exchange에서 Call C/C++ from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!