Software & AppsOperating SystemLinux

How To Fix “GLIBCXX_3.4.21 not found” Error in Matlab on Ubuntu

Ubuntu 16

When you’re using MATLAB on Ubuntu, you might encounter an error message that reads “version ‘GLIBCXX_3.4.21’ not found”. This error is typically associated with the Ubuntu R2014a version and indicates that the required version of the libstdc++ library is not available in your system. However, you can rest assured that the library version ‘GLIBCXX_3.4.21’ is present in the system’s libstdc++.so.6 file.

In this article, we’ll explore several possible solutions to resolve this issue. These include creating a symbolic link to the system’s libstdc++.so.6 file in the MATLAB directory, using the LD_PRELOAD environment variable to force MATLAB to use the system’s libstdc++.so.6 file, or upgrading the libstdc++ library to a version that includes the required GLIBCXX version.

Quick Answer

To fix the "GLIBCXX_3.4.21 not found" error in MATLAB on Ubuntu, you can try creating a symbolic link to the system’s libstdc++.so.6 file in the MATLAB directory, using the LD_PRELOAD environment variable to force MATLAB to use the system’s libstdc++.so.6 file, or upgrading the libstdc++ library to a version that includes the required GLIBCXX version.

Creating a Symbolic Link

The error message suggests that the libstdc++.so.6 file in the MATLAB directory is not compatible with the system’s GCC version. One solution is to create a symbolic link to the system’s libstdc++.so.6 file in the MATLAB directory.

To do this, open your terminal and run the following command:

ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6

In this command, ln -s creates a symbolic link, /usr/lib/x86_64-linux-gnu/libstdc++.so.6 is the source file (the system’s libstdc++.so.6 file), and /usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6 is the destination file (the libstdc++.so.6 file in the MATLAB directory).

Using the LD_PRELOAD Environment Variable

Another solution involves using the LD_PRELOAD environment variable to force MATLAB to use the system’s libstdc++.so.6 file.

To do this, run MATLAB with the following command:

LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab

In this command, LD_PRELOAD is an environment variable that can be used to load a shared library before any other library (including the C runtime, libc.so), "/usr/lib/x86_64-linux-gnu/libstdc++.so.6" is the path to the system’s libstdc++.so.6 file, and matlab is the MATLAB command.

Upgrading the libstdc++ Library

If the above solutions do not work, it may be necessary to upgrade the libstdc++ library to a version that includes the required GLIBCXX version.

To do this, add the Ubuntu Toolchain PPA, update the package list, and then upgrade the libstdc++6 package. The following commands can be used:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get upgrade libstdc++6

In these commands, sudo add-apt-repository ppa:ubuntu-toolchain-r/test adds the Ubuntu Toolchain PPA to your system, sudo apt-get update updates the package list, sudo apt-get install gcc-4.9 installs GCC 4.9, and sudo apt-get upgrade libstdc++6 upgrades the libstdc++6 package.

Conclusion

The specific steps to resolve the “GLIBCXX_3.4.21 not found” error may vary depending on the Ubuntu and MATLAB versions being used. Therefore, it’s recommended to consult the official MATLAB documentation or relevant forums for the specific version you’re using.

In some cases, the error may persist even after trying the above solutions. This could be due to different dependencies or specific configurations. In such cases, it may be helpful to seek further assistance from the MATLAB support community or consult with a technical expert.

Remember, when working with system files and commands, always ensure to have a backup and proceed with caution to avoid any system damage.

What is the GLIBCXX_3.4.21 error in MATLAB on Ubuntu?

The GLIBCXX_3.4.21 error is an error message that appears when the required version of the libstdc++ library is not found in your system. It is commonly associated with the Ubuntu R2014a version of MATLAB.

How can I fix the GLIBCXX_3.4.21 error in MATLAB on Ubuntu?

There are several possible solutions to fix the GLIBCXX_3.4.21 error in MATLAB on Ubuntu. These include creating a symbolic link to the system’s libstdc++.so.6 file in the MATLAB directory, using the LD_PRELOAD environment variable to force MATLAB to use the system’s libstdc++.so.6 file, or upgrading the libstdc++ library to a version that includes the required GLIBCXX version.

How do I create a symbolic link to the system’s libstdc++.so.6 file in the MATLAB directory?

To create a symbolic link, open your terminal and run the following command:

ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6

This command creates a symbolic link from the system’s libstdc++.so.6 file to the libstdc++.so.6 file in the MATLAB directory.

How can I use the LD_PRELOAD environment variable to fix the GLIBCXX_3.4.21 error?

You can use the LD_PRELOAD environment variable to force MATLAB to use the system’s libstdc++.so.6 file. Run MATLAB with the following command:

LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab

This command sets the LD_PRELOAD variable to the path of the system’s libstdc++.so.6 file and launches MATLAB.

What should I do if the above solutions do not work?

If the above solutions do not work, it may be necessary to upgrade the libstdc++ library to a version that includes the required GLIBCXX version. You can do this by adding the Ubuntu Toolchain PPA, updating the package list, and then upgrading the libstdc++6 package. Use the following commands:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get upgrade libstdc++6

These commands add the Ubuntu Toolchain PPA, update the package list, install GCC 4.9, and upgrade the libstdc++6 package.

What should I do if the error persists after trying the above solutions?

If the error persists even after trying the above solutions, it may be due to different dependencies or specific configurations. In such cases, it is recommended to seek further assistance from the MATLAB support community or consult with a technical expert. They may be able to provide more specific guidance based on your system and MATLAB version.

Leave a Comment

Your email address will not be published. Required fields are marked *