# Upgrade libstdc++ ###### tags: `Linux` ## Error Vscode remote-ssh cannot connect to servers with CentOS 7. ## Reason Vscode remote-ssh needs `glibc >=2.28, libstdc++ >= 3.4.25` ([source](https://code.visualstudio.com/docs/remote/linux)). We has previously upgraded the `glibc`, but for `libstdc++`, CentOS 7 only has `libstdc++.so.6.0.19` which supports up to `GLIBCXX_3.4.19`. ```shell! $ find /usr/ -name libstdc++.so.6* /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.0.19 /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo /usr/local/cuda-12.3/nsight-compute-2023.3.0/host/linux-desktop-glibc_2_11_3-x64/libstdc++.so.6 /usr/local/cuda-12.3/nsight-systems-2023.3.3/host-linux-x64/libstdc++.so.6 ``` ```shell! $ ls -l /usr/lib64/libstdc++.so.6 lrwxrwxrwx. 1 root root 19 Mar 29 2023 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19 ``` ```shell! $ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 GLIBCXX_3.4.3 GLIBCXX_3.4.4 GLIBCXX_3.4.5 GLIBCXX_3.4.6 GLIBCXX_3.4.7 GLIBCXX_3.4.8 GLIBCXX_3.4.9 GLIBCXX_3.4.10 GLIBCXX_3.4.11 GLIBCXX_3.4.12 GLIBCXX_3.4.13 GLIBCXX_3.4.14 GLIBCXX_3.4.15 GLIBCXX_3.4.16 GLIBCXX_3.4.17 GLIBCXX_3.4.18 GLIBCXX_3.4.19 GLIBCXX_DEBUG_MESSAGE_LENGTH ``` Environment: - OS: CentOS-7 - arch: x86_64 ## Install libstdc++ Choose a version that matches our requirement from [here](http://ftp.gnu.org/gnu/gcc/). We need `GLIBCXX_3.4.25`, so `GCC` has to be higher than `8.1.0` (refer to this [website](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html)). ```bash wget http://ftp.gnu.org/gnu/gcc/gcc-8.5.0/gcc-8.5.0.tar.gz tar -zxvf gcc-8.5.0.tar.gz cd gcc-8.5.0 ./contrib/download_prerequisites mkdir build && cd build ../configure --enable-languages=c,c++ --disable-multilib make -j4 make install ``` Check gain, we found that the symlink is not updated. ```shell $ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX ... GLIBCXX_3.4.19 GLIBCXX_DEBUG_MESSAGE_LENGTH ``` Update the symlink. (One can use `$ find /usr/ -name libstdc++.so.6*` to check what the new version is and where it is.) ```shell cp /usr/local/lib64/libstdc++.so.6.0.25 /usr/lib64/ rm /usr/lib64/libstdc++.so.6 ln -sf libstdc++.so.6.0.24 /usr/lib64/libstdc++.so.6 ``` --- Note that the installation changes `gcc`, which is upgraded from 8.3.1 to 8.5.0. (The path of `gcc` is changed from `/usr/bin/gcc` to `/usr/local/bin/gcc`.) ```shell $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.5.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --enable-languages=c,c++ --disable-multilib Thread model: posix gcc version 8.5.0 (GCC) $ which gcc /usr/local/bin/gcc ``` Original gcc is sill there. ```shell $ /usr/bin/gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC) ``` ## Reference 1. https://blog.csdn.net/dm569263708/article/details/125198722 ## Other Methods 1. Use `devtoolset` https://blog.csdn.net/whatday/article/details/122081503 2. A good work that solves the issue easily https://github.com/MikeWang000000/vscode-server-centos7/tree/master