因为现在的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 ~]
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)
|