1. 程式人生 > >centos7 升級gcc 7.2

centos7 升級gcc 7.2

1、gcc安裝包獲取

gcc-7.2 版本下載地址:http://gcc.parentingamerica.com/releases/gcc-7.2.0/gcc-7.2.0.tar.gz

2、安裝依賴包

isl-0.16.1.tar.bz2

gmp-6.1.0.tar.bz2

mpfr-3.1.4.tar.bz2

mpc-1.0.3.tar.bz2

依賴包下載地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/

安裝 isl-0.16.1.tar.bz2

tar -jzvf isl-0.16.1.tar.bz2

cd isl-0.16.1

./configure

make

make install

安裝 gmp-6.1.0.tar.bz2

tar -jxvf gmp-6.1.0.tar.bz2

cd gmp-6.1.0

mkdir temp

cd temp

../configure --prefix=/usr/local/gmp-6.1.0

make

make install

安裝 mpfr-3.1.4.tar.bz2

tar -jxvf mpfr-3.1.4.tar.bz2

cd mpfr-3.1.4

mkdir temp

cd temp

../configure --prefix=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-6.1.0

make

make install

安裝 mpc-1.0.3.tar.bz2

tar -jxvf mpc-1.0.3.tar.bz2

cd mpc-1.0.3

mkdir temp

cd temp

../configure --prefix=/usr/local/mpc-1.0.3 --with-mpfr=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-6.1.0

make

make install

依賴安裝完成,配置依賴引數

vim /etc/profile

在檔案尾新增:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.3/lib:/usr/local/gmp-6.1.0/lib:/usr/local/mpfr-3.1.4/lib

確保路徑與實際安裝路徑一致。

執行:

source /etc/profile

3、安裝gcc

tar -zxvf gcc-7.2.0.tar.gz

cd gcc-7.2.0

mkdir gcc-7.2-build

cd gcc-7.2-build

../configure --prefix=/usr/gcc-7.2.0 --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3

make

make install

安裝完成,init 6 重啟

4、配置gcc

使用新版gcc、g++ 替換老版本

mv /usr/bin/gcc /usr/bin/gcc.bak

ln -s /usr/gcc-7.2.0/bin/gcc /usr/bin/gcc

mv /usr/bin/g++ /usr/bin/g++.bak

ln -s /usr/gcc-7.2.0/bin/g++ /usr/bin/g++

update-alternatives --install /usr/bin/cc cc /usr/gcc-7.2.0/bin/gcc 999 

更新動態庫

cp gcc-7.2.0/output/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.24 /usr/gcc-7.2.0/lib64/libstdc++.so.6.0.24

rm -rf libstdc++.so.6

ls -s libstdc++.so.6.0.24 libstdc++.so.6

echo '/usr/local/lib/' > /etc/ld.so.conf.d/local-lib64.conf

ldconfig -v 

5、安裝完成

$ gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc-7.2.0/libexec/gcc/x86_64-pc-linux-gnu/7.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/gcc-7.2.0 --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3
Thread model: posix
gcc version 7.2.0 (GCC)