记一次源码更新GCC

因为现在的Gcc是9.4.0版本 ubuntu默认更新的版本
再我使用std::format时候发现并不支持 所以尝试升级下Gcc到最新的版本
**

root权限 如果不是root用户安装 最好前面都加上sudo

**

拉取安装包

wget https://mirrors.aliyun.com/gnu/gcc/gcc-11.3.0/gcc-11.3.0.tar.gz

// 解压GCC源码
tar -vxf gcc-11.3.0.tar.gz
mkdir build
cd build/
../configure --prefix=/usr/local/gcc-11.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib

//从日志总可以看出有如下报错,故下面每个都安装
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.

gmp安装

wget https://mirrors.aliyun.com/gnu/gmp/gmp-6.2.1.tar.bz2
tar -vxf gmp-6.2.1.tar.bz2
cd gmp-6.2.1
./configure --prefix=/usr/local/gmp-6.2.1
make
make install

MPFR编译

wget https://mirrors.aliyun.com/gnu/mpfr/mpfr-4.1.0.tar.bz2
tar -vxf mpfr-4.1.0.tar.bz2
cd mpfr-4.1.0
./configure --prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
make
make install

MPC编译

wget https://mirrors.aliyun.com/gnu/mpc/mpc-1.2.1.tar.gz
tar -vxf mpc-1.2.1.tar.gz
cd mpc-1.2.1
./configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
make
make install

GCC 配置

cd gcc-11.3.0
cd build/
../configure --prefix=/usr/local/gcc-11.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpfr=/usr/local/mpc-1.2.1
make -j4
make install

GCC版本更新

mv /usr/bin/gcc /usr/bin/gcc485
mv /usr/bin/g++ /usr/bin/g++485
mv /usr/bin/c++ /usr/bin/c++485
mv /usr/bin/cc /usr/bin/cc485


ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-10.1.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-10.1.0/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/cc


mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s /usr/local/gcc-10.1.0/lib64/libstdc++.so.6.0.28 /usr/lib64/libstdc++.so.6

脚本执行成功之后就可以查看当前使用的gcc版本了 查看的命令:gcc -v

[root@jeames007 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.1
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值