フィルターのクリア

How to manually select the libstdc++ library to use to resolve a "version 'GLIBCXX_#.#.##' not found" error?

606 ビュー (過去 30 日間)
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++?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 1 月 3 日
編集済み: MathWorks Support Team 2024 年 1 月 3 日
The errors are caused by a mismatch between the libstdc++ library shipped with Ubuntu 22.04 and MATLAB R2022b. Refer to the following link for the supported and compatible compilers for current and previous versions:
https://www.mathworks.com/support/requirements/supported-compilers-linux.html
As a workaround, you can direct MATLAB to use the system's libstdc++ library rather than the MATLAB shipped version. This can be achieved by setting the following environment variable prior to starting MATLAB:
LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
You can then force load the system libstdc++ with the expected GLIBCXX version. Note that the above command only sets the environment variable for MATLAB. To set it for other processes of the current shell, use the following commands instead:
export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6
matlab

その他の回答 (1 件)

Cris Luengo
Cris Luengo 2023 年 11 月 7 日
編集済み: Cris Luengo 2023 年 11 月 7 日
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*.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by