Linux Centos7环境下gcc由4.8升级到6.4

一、环境说明

1.使用的操作系统为centos7
2.本系统内的原GCC版本为4.8,确保机器上已安装gcc和g++,如果没有,通过如下面命令安装默认版本的gcc和g++

yum install gcc
yum install gcc-c++

二、升级过程
接下来我们需要先依次安装gmp,mpfr,mpc,这三个组件的顺序不能乱,因为后面的依次依赖前面
1、安装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

2、安装mpfr包:

wget https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.gz
tar -zxvf mpfr-4.0.2.tar.gz
cd mpfr-4.0.2         
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install

3、安装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

如果遇到报错:mul.c:175:1: error: conflicting types for ‘mpfr_fmma’

则将 mpc/src/mul.c中的 mpfr_fmma函数改名为mpfr_fmma_mul,一共三处

 

将库文件加入如下文件:

vi /etc/ld.so.conf

增加以下三行
/usr/local/gmp/lib
/usr/local/mpfr/lib
/usr/local/mpc/lib
保存退出
加完后使用如下命令更新

ldconfig -v

4、安装gcc6.4

wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.gz
tar xvf gcc-6.4.0.tar.gz
cd gcc-6.4.0
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp/lib --with-mpfr=/usr/local/mpfr/lib --with-mpc=/usr/local/mpc/lib
make -j2
make install

如遇报错

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.

解决:

yum install  gmp  gmp-devel  mpfr  mpfr-devel  libmpc  libmpc-devel

然后再重新安装

最后gcc -v查看

[root@slave2 gcc-6.4.0]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/6.4.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp/lib --with-mpfr=/usr/local/mpfr/lib --with-mpc=/usr/local/mpc/lib
Thread model: posix
gcc version 6.4.0 (GCC) 

安装成功!

 

参考链接:https://blog.csdn.net/zhuyunfei/article/details/81290764

你可能感兴趣的:(linux,c++)