CentOS7.5升級gcc到8.3.0版本
1、下載源碼包
cd /usr/local/src wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz
2、進入gcc目錄,安裝gcc依賴庫
cd gcc
./contrib/download_prerequisites
執行命令后它會自動下載mpfr、gmp、mpc isl這4個庫
如果執行報錯:tar (child): lbzip2: no exec: no file or directory
解決方法:安裝解壓軟件即可
yum -y install bzip2
3、在新目錄中配置、編譯、安裝
mkdir build cd build ../configure --prefix=/usr/local/gcc --enable-languages=c,c++ --disable-multilib make make install
編譯報錯:flex:Command not found
解決方法:安裝flex
yum -y install flex
再次編譯之前建議先清空build目錄,不然可能會報錯:error: `M4' has changed since the previous run
解決方法:清空build(你自己創建的)目錄
rm -rf /usr/local/src/gcc/build/*
如果清空了目錄,需要重新做配置再編譯
../configure --prefix=/usr/local/gcc --enable-languages=c,c++ --disable-multilib make
make install
編譯很漫長。。。我花了2個多小時。
4、修改軟鏈接后查看gcc版本
mv /usr/bin/gcc /usr/bin/gcc_old ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++_old
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++ gcc --verson
g++ --version
或者刪除之前的版本
yum -y remove gcc vim /etc/profile.d/gcc.sh export PATH=$PATH:/usr/local/gcc/bin source /etc/profile.d/gcc.sh gcc -v