1、配置gcc安装依赖环境
1.1 安装所需软件
#yum install -y gcc gcc-c++ gmp-devel bzip21.2 下载gcc包并解压
#wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-11.2.0/gcc-11.2.0.tar.gz# tar -xvf gcc-11.2.0.tar.gz1.3 配置依赖性
#cd gcc-11.2.0下载成功则提示All prerequisites downloaded successfully.
如下载失败可以手动安装依赖环境 需要下载的依赖包如下:
- gmp-6.1.0.tar.bz2
- mpfr-3.1.6.tar.bz2
- mpc-1.0.3.tar.gz
- isl-0.18.tar.bz2
下载地址:
https://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2
https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.6.tar.bz2
https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
安装gmp
#cd gmp-6.1.0#./configure --prefix=/usr/local/related/gmp-6.1.0#make && make install安装mpfr
#cd mpfr-3.1.6#./configure --prefix=/usr/local/related/mpfr-3.1.6 --with-gmp=/usr/local/related/gmp-6.1.0#make && make install安装mpc
#cd mpc-1.0.3#./configure --prefix=/usr/local/related/mpc-1.0.3 \--with-gmp=/usr/local/related/gmp-6.1.0 \--with-mpfr=/usr/local/related/mpfr-3.1.6#make && make install安装isl
#cd isl-0.18#./configure --prefix=/usr/local/related/isl-0.18 --with-gmp=/usr/local/related/gmp-6.1.0#make && make install2、安装gcc
先创建gcc构建目录
#cd gcc-11.2.0 && mkdir build && cd build添加编译参数
#../configure --prefix=/opt/gcc-11.2.0 \--enable-checking=release \--enable-languages=c,c++ \--disable-multilib
/* 手动安装依赖包需要指定路径--with-gmp=/usr/local/related/gmp-6.1.0 \--with-mpfr=/usr/local/related/mpfr-3.1.6 \--with-mpc=/usr/local/related/mpc-1.0.3*/执行无误后执行
make && make install过程会很漫长,可能需要几个小时
3、使用alternatives管理gcc
alternatives用途:通过维护符号链接,版本选择,服务选择,来确定系统默认使用的命令 先备份原gcc
#mv /usr/bin/gcc /usr/bin/gcc-4.8.5#mv /usr/bin/g++ /usr/bin/g++-4.8.5使用alternatives链接
#alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 88 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8.5#alternatives --install /usr/bin/gcc gcc /opt/gcc-10.2.0/bin/x86_64-pc-linux-gnu-gcc 99 --slave /usr/bin/g++ g++ /opt/gcc-10.2.0/bin/x86_64-pc-linux-gnu-g++使用alternatives选择系统默认gcc版本
#alternatives --config gcc
There are 2 programs which provide 'gcc'.
Selection Command----------------------------------------------- 1 /usr/bin/gcc-4.8.5*+ 2 /opt/gcc-11.2.0/bin/x86_64-pc-linux-gnu-gcc
Enter to keep the current selection[+], or type selection number: 2 //此处输入序号选择gcc版本查看当前gcc版本
#gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/opt/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured with: ../configure --prefix=/opt/gcc-11.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilibThread model: posixSupported LTO compression algorithms: zlibgcc version 11.2.0 (GCC)
#g++ -vUsing built-in specs.COLLECT_GCC=g++COLLECT_LTO_WRAPPER=/opt/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured with: ../configure --prefix=/opt/gcc-11.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilibThread model: posixSupported LTO compression algorithms: zlibgcc version 11.2.0 (GCC)4、更新库链接
不更新库链接一般会报以下错误:
/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.21' not found/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.22' not found两种方式更新 第一种简单粗暴
#find / -name libstdc++.so.6#rm -rf /usr/lib64/libstdc++.so.6#ln -s /opt/gcc-11.2.0/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6第二种新增
#echo "/opt/gcc-11.2.0/lib64" >> /etc/ld.so.conf#ldconfig查看目前包含哪些库
#strings /usr/lib64/libstdc++.so.6 | grep GLIBCGLIBCXX_3.4GLIBCXX_3.4.1GLIBCXX_3.4.2GLIBCXX_3.4.3GLIBCXX_3.4.4GLIBCXX_3.4.5GLIBCXX_3.4.6GLIBCXX_3.4.7GLIBCXX_3.4.8GLIBCXX_3.4.9GLIBCXX_3.4.10GLIBCXX_3.4.11GLIBCXX_3.4.12GLIBCXX_3.4.13GLIBCXX_3.4.14GLIBCXX_3.4.15GLIBCXX_3.4.16GLIBCXX_3.4.17GLIBCXX_3.4.18GLIBCXX_3.4.19GLIBCXX_3.4.20GLIBCXX_3.4.21GLIBCXX_3.4.22GLIBCXX_3.4.23GLIBCXX_3.4.24GLIBCXX_3.4.25GLIBCXX_3.4.26GLIBCXX_3.4.27GLIBCXX_3.4.28GLIBCXX_3.4.29