#备份旧版
cd /bin
mv gcc gcc485
mv g++ g++485
mv c++ c++485
#删除之前的低版本软链接
rm -rf /usr/bin/gcc
rm -rf /usr/bin/g++
rm -rf /usr/bin/c++
#下载地址 https://ftp.gnu.org/gnu/gcc/
#下载编译
wget https://ftp.gnu.org/gnu/gcc/gcc-11.3.0/gcc-11.3.0.tar.gz --no-check-certificate
或者 wget https://ftp.gnu.org/gnu/gcc/gcc-11.3.0/gcc-11.3.0.tar.xz --no-check-certificate
tar -xvf gcc-11.3.0.tar.gz #或 tar -xvf gcc-11.3.0.tar.xz
cd gcc-11.3.0
#./configure --enable-languages=c,c++,fortran --disable-multilib --prefix=$HOME/.gcc/11.3.0
./configure -prefix=/usr/local/gcc-6.5.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
./configure -prefix=/usr/local/gcc-11.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
make -j
make install
#建立新版本软连接
ln -s /usr/local/gcc-11.3.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-11.3.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-11.3.0/bin/c++ /usr/bin/c++
#建立新版本软连接
ln -s /usr/local/gcc-6.5.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-6.5.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-6.5.0/bin/c++ /usr/bin/c++
#查看新本
gcc --version
gcc4.8.5
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz
#安装C和C++的静态库
yum install -y glibc-static libstdc++-static
#安装旧版本的gcc、c++编译器
yum install gcc gcc-c++
tar -xvf gcc-4.8.5.tar.gz
cd gcc-4.8.5
#下载一些必备的依赖程序
./contrib/download_prerequisites
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
./configure -prefix=/usr/local/gcc-4.8.5
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make
make install
ln -s /usr/local/gcc-4.8.5/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-4.8.5/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-4.8.5/bin/c++ /usr/bin/c++
编译&安装gmp
官方地址https://gmplib.org/
wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
tar -xvf gmp-6.2.1.tar.xz
cd gmp-6.2.1
./configure -prefix=/usr/local/gmp-6.2.1
make && make install
ll /usr/local/gmp-6.2.1
编译&安装mpfr
https://mpfr.loria.fr/mpfr-current/
wget https://mpfr.loria.fr/mpfr-current/mpfr-4.1.0.tar.gz
tar -xvf mpfr-4.1.0.tar.gz
cd mpfr-4.1.0
./configure -prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
make && make install
ll /usr/local/mpfr-4.1.0
编译&安装mpc
https://ftp.gnu.org/gnu/mpc/
wget https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz --no-check-certificate
tar -xvf 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
ll /usr/local/mpc-1.2.1
如果找不到gmp的链接库,则执行如下命令:
ln -s /usr/local/gmp-6.2.1/lib/libgmp.la /usr/local/lib/libgmp.la
ln -s /usr/local/gmp-6.2.1/lib/libgmp.so /usr/local/lib/libgmp.so
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.2.1/lib:/usr/local/gmp-6.2.1/lib:/usr/local/mpfr-4.1.0/lib
编译报错:error: cannot compute suffix of object files: cannot compile
在/etc/profile 最后添加以下内容:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.2.1/lib:/usr/local/gmp-6.2.1/lib:/usr/local/mpfr-4.1.0/lib
source /etc/profile
重新make