环境:
系统:CentOS 7
编译安装:
下载源码包:https://gcc.gnu.org/
安装依赖库:
安装gmp
# wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
# tar xvf gmp-6.1.2.tar.xz
# cd gmp-6.1.2
# ./configure --prefix=/usr/local/gmp
# make && make install
安装mpfr
# wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.gz
# tar xvf mpfr-3.1.5.tar.gz
# cd mpfr-3.1.5
# ./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
# make && make install
安装mpc
# wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
# tar xvf mpc-1.0.3.tar.gz
# cd mpc-1.0.3
# ./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp -with-mpfr=/usr/local/mpfr
# make && make install
安装依赖包
# yum install libgcc gcc-c++
安装gcc
# tar xvf gcc-6.4.0.tar.gz
# cd gcc-6.4.0
# ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
# make -j 8
# make install
编辑变量:
# vi /etc/ld.so.conf
/usr/lib64
/usr/local/gmp/lib
/usr/local/mpfr/lib
/usr/local/mpc/lib
更新状态库
# ldconfig -v
备份系统默认的gcc版本
# mv /usr/bin/gcc /usr/bin/gcc-bak
# mv /usr/bin/g++ /usr/bin/g++-bak
# mv /usr/bin/c++ /usr/bin/c++-bak
新版本gcc创建软链接
# ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
# ln -s /usr/local/gcc/bin/c++ /usr/bin/c++
# ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
# ln -s /usr/local/gcc/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6
查看gcc版本
# gcc --version