最近要开始接手C++的项目,发现项目环境还在centos7.9上,很多依赖都是低版本的,想要vscode远程调试,发现要依赖gclibc2.18,没办法只好自己编译一个。
yum install -y epel-release
yum install -y bison wget bzip2 gcc gcc-c++ glibc-headers编译make
# Download and extract make source
wget http://ftp.gnu.org/gnu/make/make-4.2.1.tar.gz
tar -zxvf make-4.2.1.tar.gz
cd make-4.2.1
# Build and install make
mkdir build
cd build
../configure --prefix=/usr/local/make && make && make install
# Update PATH and create a symbolic link for compatibility
export PATH=/usr/local/make/bin:$PATH
ln -s /usr/local/make/bin/make /usr/local/make/bin/gmake
# Verify the updated make version
make -v安装gcc8
# Install Software Collections (SCL) repository
yum install -y centos-release-scl
#因为centos7.9已经不维护,需要更换阿里云
1. vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
注释掉mirrorlist那行
增加baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
2. vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
注释掉mirrorlist那行
增加baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
yum repolist
yum clean all
yum makecache
# Install GCC and related tools from DevToolset 8
yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
# Enable DevToolset 8
echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
source /etc/profile
# Download and extract glibc source
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
tar -xvf glibc-2.28.tar.xz
cd glibc-2.28
#修改编译脚本
vi scripts/test-installation.pl
126 if ($name ne "nss_ldap" && $name ne "db1"
127 && $name ne "thread_db"
128 && $name ne "nss_test2" <-- 增加这个
129 && $name ne "nss_test1" && $name ne "libgcc_s") {
130 $link_libs .= " -l$name";
131 $versions{$name} = $version;
132 }
# Build and install glibc
mkdir build
cd build
如果编译时报undefined reference to '_nsl_default_nss@GLIBC_PRIVATE'错误,
可以在../configure命令最后没添加 --enable-obsolete-nsl(注意空格)
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl
make -j4
make install
# Resolve encoding issues and install localization data
make localedata/install-locales# Verify the installed GLIBC version
strings /lib64/libc.so.6 | grep ^GLIBC_如果发现还需要GLIBCXX和CXXABI,比如:
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
cd /use/lib64
# 下载文件
wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26
# 建立软连接
ln -snf ./libstdc++.so.6.0.26 libstdc++.so.6
参考地址
https://github.com/legendzzzaioi/centos7-install-glibc2.28
https://www.cnblogs.com/Jedi-Pz/p/18447117
https://www.mmxiaowu.com/article/65b8b782a9575759ba2f59cb