升级GCC 7.3后RHEL服务器缺失GLIBCXX_3.4.21与CXXABI_1.3.9问题求助
CXXABI_1.3.9 and GLIBCXX_3.4.21 Errors After GCC 7.3.0 Installation on RHEL (Maipo) Hey Leo, I’ve run into this exact issue plenty of times—compiling a newer GCC doesn’t automatically make the system use its updated libraries, which is why you’re hitting those version errors. Let’s walk through how to fix this step by step:
1. Locate the New GCC’s libstdc++ Library
First, find where your compiled GCC 7.3.0 installed its libstdc++.so.6 file. By default, this is usually in a subdirectory under /usr/local (since you compiled from source). Run this command to track it down:
find /usr/local -name "libstdc++.so.6"
You’ll likely get a path like /usr/local/gcc-7.3.0/lib64/libstdc++.so.6 or /usr/local/lib64/libstdc++.so.6.
2. Verify the New Library Supports the Required Versions
Double-check that this new library actually includes the CXXABI_1.3.9 and GLIBCXX_3.4.21 versions you need. Run:
strings /path/to/your/new/libstdc++.so.6 | grep -E "(CXXABI|GLIBCXX)"
Scroll through the output—you should see both version strings listed (GCC 7.3.0 definitely ships with these, so this is just a sanity check).
3. Make the System Use the New Library
The problem is that your system’s dynamic linker is still looking for the old libstdc++.so.6 in /lib64 instead of your new GCC’s directory. Here are your options:
Option 1: Temporary Fix (For Testing)
If you just need to run a single application once, set the LD_LIBRARY_PATH environment variable temporarily:
export LD_LIBRARY_PATH=/path/to/your/new/gcc/lib64:$LD_LIBRARY_PATH # Now run your software ./your-application
This only affects your current shell session—close the terminal and the setting goes away.
Option 2: Permanent System-Wide Fix (Recommended)
To make the change apply to all users and processes:
- Create a new config file in
/etc/ld.so.conf.d/to tell the linker about the new library path:echo "/path/to/your/new/gcc/lib64" > /etc/ld.so.conf.d/gcc7.conf - Update the linker cache to apply the change:
ldconfig -v
Now any application that needs the newer libstdc++ versions will automatically use the GCC 7.3.0 library.
Option 3: Per-Application Fix (No System-Wide Changes)
If you don’t want to modify the entire system’s library setup, you can force a specific application to use the new library with LD_PRELOAD:
LD_PRELOAD=/path/to/your/new/libstdc++.so.6 ./your-application
Critical Note: Don’t Replace the System’s Default libstdc++!
Resist the urge to overwrite /lib64/libstdc++.so.6 with the new version. Many core system tools (like bash, yum, etc.) depend on the old library, and replacing it could break your entire system. The methods above are safe because they add the new path without replacing the old one.
内容的提问来源于stack exchange,提问作者Leo

