How to solve error on CentOS "/lib64/libstdc++.so.6 version GLIBCXX_3.4.xx not found"


My personal server uses CentOS 7.9, and there are often strange errors when deploying some AI applications.
For example, recently, an error was reported when deploying an application:

1
/lib64/libstdc++.so.6: version GLIBCXX_3.4.xx not found

Online search for solutions, there are different opinions, either reinstall gcc, or recompile and install libstdc++,export LD_LIBRARY_PATH and so on.
Several attempts have failed, and there is no way to upgrade the os version. Finally, a suitable solution is found, and it’s worked for me.

  1. Find and display all packages that provide libstdc++.so.6 as a library file through yum
1
sudo yum provides libstdc++.so.6
  1. Download new version libstdc.so.

NOTICE: Since I need version 3.4.22+, so I can just update it to 3.4.26. Other versions are the same.

1
2
3
cd /usr/local/lib64
sudo wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip
unzip libstdc.so_.6.0.26.zip
  1. Copy libstdc++.so.6.0.26 to /usr/lib64
1
2
cp libstdc++.so.6.0.26 /usr/lib64
cd /usr/lib64
  1. Check the soft link version of libstdc++.so.6,
1
ls -l | grep libstdc++

It may shows like this:

1
libstdc++.so.6 ->libstdc++.so.6.0.19
  1. Remove /usr/lib64 original link libstdc++.so.6, you can backup it before remove.
1
sudo rm libstdc++.so.6

then, relink it.

1
sudo ln -s libstdc++.so.6.0.26 libstdc++.so.6
  1. OK, check the newest link
1
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

It may shows like this:

1
2
3
4
5
GLIBCXX_3.4
...
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_DEBUG_MESSAGE_LENGTH

Well Done!