Borrar filtros
Borrar filtros

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

574 visualizaciones (últimos 30 días)
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++?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 3 de En. de 2024
Editada: MathWorks Support Team el 3 de En. de 2024
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 comentario
Cris Luengo
Cris Luengo el 7 de Nov. de 2023
This should be either
LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
or
export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6
matlab
In the first case the environment is set only for the MATLAB process, in the second case it is set for the current shell session.

Iniciar sesión para comentar.

Más respuestas (1)

Cris Luengo
Cris Luengo el 7 de Nov. de 2023
Editada: Cris Luengo el 7 de Nov. de 2023
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*.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by