Centos 7.9 GLIBC GCC 升级

Administrator
发布于 2024-03-20 / 26 阅读
0
0

Centos 7.9 GLIBC GCC 升级

Centos 7.9 GLIBC GCC 升级

建议不要升,直接Centos 7 升 Centos 8

系统版本信息

	cat /etc/redhat-release
	CentOS Linux release 7.9.2009 (Core)

安装 GCC

清华源

https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/

选择合适的版本,我这里选择的是 gcc-12.3.0.tar.gz

具体步骤

	# 下载	
	wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.gz
	
	# 解压
	tar -zxvf gcc-12.3.0.tar.gz
	cd gcc-12.3.0/

	# 下载额外的包(可能时间比较长)
	./contrib/download_prerequisites
	
	# 编译
	./configure --enable-checking=release  --disable-multilib
	make -j12
	
	# 安装
	sudo make install -j12

安装 GLIBC

安装前的准备

安装 bison

	sudo yum install bison -y

安装 make

这里是源码安装,选择make 4.3,不要选择make 4.4 可能会卡住

https://ftp.gnu.org/gnu/make/

	# 下载
	wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
	
	# 解压
	tar -zxvf make-4.3.tar.gz
	cd make-4.3
	
	# 编译
	./configure
	make -j12
	
	# 安装
	sudo make install -j12

	# 替换
	sudo /usr/local/bin/make /usr/bin/make

GLIBC 正式安装

选择的是 glibc 2.28 版本

	# 下载
	git clone https://mirrors.tuna.tsinghua.edu.cn/git/glibc.git
	cd glibc
	git checkout -b glibc-2.28 glibc-2.28
	
	# 编译(我的gcc是 12.3, 需要加--disable-werror选项,--enable-obsolete-nsl 是为了解决后面的问题而加的)
	mkdir build && cd build
	../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-werror --enable-obsolete-nsl		
	make -j12
	
	# 安装
	# /usr/bin/ld: cannot find -lnss_test2 问题的解决方案
	diff --git a/scripts/test-installation.pl b/scripts/test-installation.pl
	index b2e4ba7646..2b70f11c1b 100755
	--- a/scripts/test-installation.pl
	+++ b/scripts/test-installation.pl
	@@ -125,7 +125,7 @@ while (<SOVERSIONS>) {
	     next if ($build_mathvec == 0 && $name eq "mvec");
	     if ($name ne "nss_ldap" && $name ne "db1"
	        && $name ne "thread_db"
	-       && $name ne "nss_test1" && $name ne "libgcc_s") {
	+       && $name ne "nss_test1" && $name ne "nss_test2" && $name ne "libgcc_s") {
	       $link_libs .= " -l$name";
	       $versions{$name} = $version;
	     }
	# undefined reference to ‘_nsl_default_nss@GLIBC_PRIVATE’的解决方案就是前面的--enable-obsolete-nsl 选项

	sudo make install -j12
	
	# 替换 
	sudo ln -s /usr/lib64/libc-2.28.so /usr/lib64/libc.so.6
	sudo ln -s /usr/local/lib64/libstdc++.so.6.0.30 /usr/lib64/libstdc++.so.6


评论