Linux下升级gcc8.2

1、背景

给某厂商做交叉编译的时候,它们的链接器ld提示:
/lib64/libc.so.6: version GLIBC_2.27' not found

解决办法:
① 升级glibc版本;(但是编译升级glibc-2.27,提示我gcc版本太低,所以需要先升级gcc版本)
② 更改 “链接器运行时的动态链接目录” ;(因为我的机器上有两个其他进程下载的gcc-8 gcc-10的编译器包,但是没有配到环境变量内,因此也可以采用替换动态链接的目录到新的gcc版本下试试)

这里使用方案①,主要讲如何升级gcc,为后面有类似升级需求做笔记;

2、升级gcc

2.1 跳坑

坑笔记多,都踩了个遍之后发现官网手册写的非常简单! 直接:

rm -rf gcc-8.2.0;
tar -zxvf gcc-8.2.0.tar.xz;

!! 全部重新开始 !!

2.2 正式开始

# 1.进入gcc目录
cd gcc-8.2.0;

# 2.下载依赖包
./contrib/download_prerequisites # 下载非常慢的话,可以手动下载然后在手动解压

# 3.修改./contrib/download_prerequisites不在进行下载,直接进行后续建立软连接操作(按照下面把wget和curl注掉)
--- ./contrib/download_prerequisites	2022-03-31 19:33:37.094850629 +0800
+++ ./contrib/download_prerequisites_backup	2022-03-31 19:50:17.232499843 +0800
@@ -56,11 +56,9 @@
 esac

 if type wget > /dev/null ; then
- # fetch='wget'
-	echo "1"
+  fetch='wget'
 else
- # fetch='curl -LO -u anonymous:'
-	echo "2"
+  fetch='curl -LO -u anonymous:'
 fi
 chksum_extension='sha512'
 directory='.

# 4.执行configure,并编译
mkdir output_gcc;
cd output_gcc;

../configure \
	--prefix=/usr/local \
	-enable-checking=release \
	-enable-languages=c,c++ \
	--disable-multilib

make -j 9
make install

官网手册说明:

The difficult way, which is not recommended, is to download the sources for GMP, MPFR and MPC, then configure and install each of them in non-standard locations, then configure GCC with --with-gmp=/some/silly/path/gmp --with-mpfr=/some/silly/path/mpfr --with-mpc=/some/silly/path/mpc, then be forced to set LD_LIBRARY_PATH=/some/silly/path/gmp:/some/silly/path/mpfr:/some/silly/path/mpc/lib in your environment forever. This is silly and causes major problems for anyone who doesn’t understand how dynamic linkers find libraries at runtime. Do not do this. If building GCC fails when using any of the --with-gmp or --with-mpfr or --with-mpc options then you probably shouldn’t be using them.

翻译:

最困难的方法是下载 GMP、 MPFR 和 MPC 的源代码,然后在非标准位置配置并安装每个源代码,然后将 GCC 配置为
–with-GMP=/some/silly/path/GMP --with-MPFR =/some/silly/path/MPFR --with-MPC =/some/silly/path/MPC,然后强制设置 LD_library_path =/some/some/:/path/GMP:/some/silly/path/fr:/some/MPFR:/some/silly/path/MPC/lib/
在你环境变量中。 这是愚蠢的,对于那些不理解动态链接器如何在运行时查找库的人来说,这会导致很大的问题。不要这样做。如果在使用
–with-gmp 或 --with-mpfr 或 --with-mpc 选项时构建 GCC 失败,那么您可能不应该使用它们。

而网上大多数教程都是这样做,全部下下来,自己手动编译一遍,然后在make编译过程中,非常多问题!! 很恶心人。 建议直接按照官网指示这样来进行编译升级。
(对于下载慢的问题,可以自己手动在本机下,有代理很快)

参考官网手册说明:https://gcc.gnu.org/wiki/InstallingGCC

3、更改“链接器运行时的动态链接目录”

没继续调研了,后续有时间在调研+补;

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值