gcc升级到6.3.0版本

虚拟机环境信息:

[root@localhost /]# cat /etc/redhat-release

CentOS Linux release 7.3.1611 (Core)

[root@localhost /]# cat /proc/version

Linux version 3.10.0-514.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016

可以看出gcc版本为4.8.5

GCC依赖于gmp 4.2+, mpfr 2.4+和mpc 0.8+,这里直接下载安装最新的版本。

安装gmp 6.1.2
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 -j20 && make install
(执行./configure –prefix=/usr/local/gmp时会出现错误 configure: error: could not find a working compiler。直接yum remove gcc 卸载然后 yum install gcc 重新安装再执行上述操作)

执行./configure –prefix=/usr/local/gmp 可能会出现如下错误
checking whether sscanf needs writable input… no
checking for struct pst_processor.psp_iticksperclktick… no
checking for suitable m4… configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).

那就安装m4

yum install m4

安装成功后再次执行configure命令成功会显示如下界面

config.status: linking mpn/x86_64/coreihwl/gmp-mparam.h to gmp-mparam.h

config.status: executing libtool commands
configure: summary of build options:

Version: GNU MP 6.1.2
Host type: haswell-pc-linux-gnu
ABI: 64
Install prefix: /usr/local/gmp
Compiler: gcc -std=gnu99
Static libraries: yes
Shared libraries: yes

安装mpfr 3.1.5 mpfr依赖于gmp
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 -j20 && make install

安装mpc 1.0.3 mpc依赖于gmp和mpfr
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 -j20 && make install

安装GCC 6.3.0
wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xvf gcc-6.3.0.tar.gz
cd gcc-6.3.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 -j20&&make install

安装过程中可能会出现:
“checking for suffix of object files… configure: error: cannot compute suffix of object files: cannot compile

See `config.log’ for more details.

make[2]: * [configure-stage1-target-libgcc] Error 1

make[2]: Leaving directory `/tmp/gcc-6.3.0’

make[1]: * [stage1-bubble] Error 2

make[1]: Leaving directory `/tmp/gcc-6.3.0’

make: * [bootstrap] Error 2

解决方法:
yum install m4
yum install gcc-c++

实际解决办法:编辑变量,把我们安装的gmp,mpfr,mpc加进去
vi /etc/ld.so .conf

添加部分:
/usr/local/lib #这个是默认系统的变量
/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 -sf /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -sf /usr/local/gcc/bin/c++ /usr/bin/c++
ln -sf /usr/local/gcc/bin/g++ /usr/bin/g++
ln -sf /usr/local/gcc/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6

查看gcc版本:
[root@localhost ~]# gcc –version
gcc (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

或者

[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./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
Thread model: posix
gcc version 6.3.0 (GCC)

你可能感兴趣的:(gcc升级到6.3.0版本)