背景就是我需要在 VSCode 上开发 c++ 代码,安装了 clangd 插件之后不生效,然后执行 /home/impala/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/17.0.3/clangd_17.0.3/bin/clangd --version 发现有报错,找不到 GLIBC-2.18,通过 yum 安装的 glibc 最高版本是 2.17 所以需要手动升级。

# glibc 升级

wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.18.tar.gz
tar -zxf glibc-2.18.tar.gz
cd glibc-2.31/
mkdir build
cd build
sudo ../configure  --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror
sudo make -j8
sudo make install

# 问题

在执行 sudo ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror 这步,遇到了报错:
LD_LIBRARY_PATH shouldn't contain the current directory when building glibc. Please change the environment variable and run configure again.
然后我执行 echo $LD_LIBRARY_PATH 结果是 /opt/impala/toolchain/toolchain-packages-gcc7.5.0/gcc-7.5.0/lib64/:
../configure 文件中搜索 LD_LIBRARY_PATH ,可以看到:

# Test if LD_LIBRARY_PATH contains the notation for the current directory
# since this would lead to problems installing/building glibc.
# LD_LIBRARY_PATH contains the current directory if one of the following
# is true:
# - one of the terminals (":" and ";") is the first or last sign
# - two terminals occur directly after each other
# - the path contains an element with a dot in it

所以环境变量开头和结尾不能有 :; ,所以执行了 export LD_LIBRARY_PATH=/opt/impala/toolchain/toolchain-packages-gcc7.5.0/gcc-7.5.0/lib64/ ,然而再次执行 ../configure 还是报同样的错。
后来意识到,我不是在 root 用户下执行的 export ,干脆切到 root 用户来升级,这下就好了。

# 总结

看起来复杂的问题,其实最终会发现都是比较简单的原因,遇到问题还是应该冷静耐心的分析解决。