1 背景
由于软件更新后,要求的glibc、stdc++等版本较高,centos yum包中可安装版本太低,于是进行源码编译升级
2 当前系统版本及GLIBC版本信息
3 升级GCC
预安装包 安装过程中需要makeinfo, 先安装下texi2html, texinfo。一定要安装,否则编译时会报错
shell
yum install texi2html texinfo gcc gcc-c++3.1 安装过程
shell
cd /usr/local/src
wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
tar -zxf gcc-9.3.0.tar.gz
cd gcc-9.3.0/
./contrib/download_prerequisites # 下载依赖环境。如果网络不好,可以先手动下载依赖的这四个包,下载地址ftp://gcc.gnu.org/pub/gcc/infrastructure/
cat /proc/cpuinfo| grep "processor"| wc -l
mkdir build
cd build
../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr
make -j$(nproc) # 这一步比较漫长
make install3.2 升级完成后gcc版本检查
shell
cd /usr/lib64
ll libstdc++*
gcc -v
gcc --version3.3 安装遇到的问题及解决办法
make[1]: *** [stage1-bubble] 错误
原因是没有c++库,用以下命令安装即可 解决办法:yum install gcc-c++
4 升级make
shell
cd /usr/local/src
wget https://mirrors.aliyun.com/gnu/make/make-4.3.tar.gz
tar -zxf make-4.3.tar.gz
cd make-4.3/
mkdir build
cd build
../configure --prefix=/usr && make && make install5 升级glibc-2.31
如果升级2.31版本,make一定不要用4.4,否则会hang住。 https://github.com/crosstool-ng/crosstool-ng/pull/1990
5.1 依赖
yum install python3 binutils
5.2 安装
shell
cd /usr/local/src
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.31.tar.gz
tar -zxf glibc-2.31.tar.gz
cd glibc-2.31/
cat INSTALL | grep -E "newer|later"
mkdir build
cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror --enable-obsolete-nsl
make -j$(nproc)
make install
make localedata/install-locales5.3 报错及解决
问题 make install 报错
shell
/usr/bin/perl scripts/test-installation.pl /tmp/glibc-2.31/build/
/usr/bin/ld: cannot find -lnss_test2
...
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl
scripts/test-installation.pl /tmp/glibc-2.31/build/
/usr/bin/ld: /lib/../lib64/libnss_nis.so: undefined reference to
'_nsl_default_nss@GLIBC_PRIVATE'可以从上面脚本信息看到是 scripts/test-installation.pl 有报错, 进去看一下, 主目录下的 Makefile
shell
122 ifneq (no,$(PERL))
123 ifeq (/usr,$(prefix))
124 ifeq (,$(install_root))
125 LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/
test-installation.pl $(common-objpfx)
126 endif
127 endif
128 endif
129 endif
130 endif123 ifeq (/usr,$(prefix)) 看来是和configure配置的prefix设置为/usr有关
具体的脚本 scripts/test-installation.pl 大致流程:
- 读取共享库版本;
- 使用这些动态库生成一个文件;
- 通过ldd检验一下
5.3.1 解决动态库 nss_test2 报错
找到类似这样的几行,添加&& $name ne "nss_test2"即可
shell
if ($name ne "nss_ldap" && $name ne "db1"
&& $name ne "thread_db"
&& $name ne "nss_test2" # 新增加
&& $name ne "nss_test1" && $name ne "libgcc_s") {
$link_libs .= " -l$name";
$versions{$name} = $version;
}5.3.2 解决动态库 undefined reference to '_nsl_default_nss@GLIBC_PRIVATE'
configure时增加 --enable-obsolete-nsl
6 参考
https://garlicspace.com/2020/07/18/centos7-升级-glibc-gcc/#nss_test2