解决方式参考:Using Visual Studio Code for C Programming on an Old Linux Remote Server
1. 检查问题:
$ cd $HOME/.vscode-server/bin/74b1f979648cc44d385a2286793c226e611f59e7
$ ./node # 出现以下输出说明C++版本不够
# ./node: /usr/lib64/libc.so.6: version `GLIBC_2.16' not found (required by ./node)
# ./node: /usr/lib64/libc.so.6: version `GLIBC_2.17' not found (required by ./node)
$ strings /lib64/libc.so.6 | grep GLIBC # 目前最高版本2.15,而最低要求是2.17
...
GLIBC_2.14
GLIBC_2.15
GLIBC_PRIVATE
2. 以非管理员身份安装这些库
2.1. 下载库文件:
- glibc (the GNU C standard library): glibc-2.17–307.el7.1.x86_64.rpm
- libstdc++ (C++ standard library): libstdc++-4.8.5–39.el7.x86_64.rpm
2.2. 建立伪root安装目录,把待安装文件放在里面
$ mkdir ~/local && cd ~/local
$ ll
-rw-rw-r-- 1 liuwei2019 bioX 3817244 May 19 20:50 glibc-2.17-326.el7_9.x86_64.rpm
-rw-rw-r-- 1 liuwei2019 bioX 816216 Jul 23 11:26 libstdc++-4.8.5-44.el7.x86_64.rpm
-rw-rw-r-- 1 liuwei2019 bioX 72524 Nov 13 2018 patchelf-0.9-10.sdl7.x86_64.rpm
2.3. 解压抽取,创建类似于root用户的安装结构
$ rpm2cpio glibc-2.17-326.el7_9.x86_64.rpm | cpio -idmv
$ rpm2cpio libstdc++-4.8.5-44.el7.x86_64.rpm | cpio -idmv
2.4. 检查glibc版本
$ find . -name "lib*.so.6"
$ strings ./lib64/libc.so.6 | grep GLIBC
...
GLIBC_2.16
GLIBC_2.17 # 满足需求
GLIBC_PRIVATE
$ strings ./usr/lib64/libstdc++.so.6 | grep GLIBCXX
...
GLIBCXX_3.4.18
GLIBCXX_3.4.19 # 满足需求
GLIBCXX_DEBUG_MESSAGE_LENGTH
2.5. 重新链接
现在需要告诉VSCode使用新安装的库,一个天真的想法是改变$LD_LIBRARY_PATH
环境变量检查local文件夹,但是这会导致其它的命令不可用并且导致你无法再连上服务器(不要尝试) 。我们需要改变的是可执行文件的链接,此时需要一个包:patchelf-0.9–10.el7.x86_64.rpm,这个包里面我们只需要保留patchelf
命令,因此将它解压到一个临时目录,再把这个命令拷过来:
插曲,我在这里下载 rpm.pbone.net/results_lim… 的 rpm.pbone.net/info_idpl_6…
然后一直报错,说需要GLBC_2.14。然后我发现刚才的网页下面说需要libc.so.6(GLIBC_2.14)(64bit)
所有我又回到最初的网页,找的了一个不需要的:rpm.pbone.net/info_idpl_5…
$ mkdir ../tmp && cd ../tmp
$ rpm2cpio patchelf-0.9-10.sdl7.x86_64.rpm | cpio -idmv
./usr/bin/patchelf
./usr/share/doc/patchelf-0.9
./usr/share/doc/patchelf-0.9/README
./usr/share/licenses/patchelf-0.9
./usr/share/licenses/patchelf-0.9/COPYING
./usr/share/man/man1/patchelf.1.gz
333 blocks
$ mkdir -p ~/bin
$ cp usr/bin/patchelf ~/bin
$ cd ..
$ rm -rf tmp/ #删除临时目录
之后进入 VSCode 目录运行以下代码:
$ cd $HOME/.vscode-server/bin/74b1f979648cc44d385a2286793c226e611f59e7
$ ~/bin/patchelf --set-interpreter $HOME/local/lib64/ld-linux-x86-64.so.2 --set-rpath $HOME/local/usr/lib64/:$HOME/local/lib64 node
2.6. 检查是否成功
上面的命令没有输出的话可以认为没有错误,让我们检查一下:
(不一定有下面的输出)
$ ldd node
...
linux-vdso.so.1 (0x00007fff1ebff000)
libdl.so.2 => /home/liuwei2019/local/lib64/libdl.so.2 (0x00007f0a29af1000)
libstdc++.so.6 => /pub5/xiaoyun/BioSoftware/MATLAB/MATLAB_Compiler_Runtime/v714/sys/os/glnxa64/libstdc++.so.6 (0x00007f0a297eb000)
libm.so.6 => /home/liuwei2019/local/lib64/libm.so.6 (0x00007f0a294e9000)
libgcc_s.so.1 => /pub5/xiaoyun/BioSoftware/MATLAB/MATLAB_Compiler_Runtime/v714/sys/os/glnxa64/libgcc_s.so.1 (0x00007f0a292d2000)
libpthread.so.0 => /home/liuwei2019/local/lib64/libpthread.so.0 (0x00007f0a290b6000)
libc.so.6 => /usr/lib64/libc.so.6 (0x000000390ee00000)
/home/liuwei2019/local/lib64/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x000000324d200000)