【Tools】gcc4.4升级到gcc4.8
00.目錄
- 00.目錄
- 01. 簡介
- 02. 軟件包下載
- 03. 安裝gmp
- 04. 安裝mpfr
- 05. 安裝mpc
- 06. 安裝gcc
- 07. 錯誤排查(可選 )
01. 簡介
由于gcc4.4不支持C++11新特性,所以將Redhat6.5中gcc4.4升級到gcc4.8. 本文介紹在系統無法連接互聯網的情況下,如何升級GCC。離線和在線升級的主要區別在于,如果可以聯網,在升級gcc前的需要安裝的依賴包,可以通過運行gcc安裝包下的腳本自行下載安裝,免去了很多的麻煩。
環境:RedHat6.5
首先下載gcc安裝包,本文為gcc-4.8.5.tar.gz,解壓后,如果直接運行安裝目錄下的configure腳本,可能會因為當前系統的GMP,MPFR,MPC的版本過低而拋出如下的錯誤
02. 軟件包下載
需要使用的安裝包為 gcc-4.8.5.tar.gz,gmp-5.0.5.tar.bz2,mpfr-3.0.1.tar.gz,mpc-1.0.1.tar.gz.
如果是在聯網環境,可以運行安裝目錄下的”./contrib/download_prerequisites”腳本來下載相關的依賴。而由于我們是在局域網內,所以需要到因特網中下載這三個安裝包,然后逐個安裝:
download_prerequisites腳本內容如下:
#! /bin/sh # Download some prerequisites needed by gcc. # Run this from the top level of the gcc source tree and the gcc # build will do the right thing. # # (C) 2010 Free Software Foundation # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.MPFR=mpfr-2.4.2 GMP=gmp-4.3.2 MPC=mpc-0.8.1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1 tar xjf $MPFR.tar.bz2 || exit 1 ln -sf $MPFR mpfr || exit 1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1 tar xjf $GMP.tar.bz2 || exit 1 ln -sf $GMP gmp || exit 1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1 tar xzf $MPC.tar.gz || exit 1 ln -sf $MPC mpc || exit 1rm $MPFR.tar.bz2 $GMP.tar.bz2 $MPC.tar.gz || exit 1下載鏈接:
gcc下載鏈接:gcc-4.8.5下載
gmp下載鏈接:gmp-5.0.5下載
mpfr下載鏈接:mpfr-3.0下載
mpc下載鏈接: mpc-1.0.1下載
03. 安裝gmp
GMP是一個任意精度的開源算術庫,可用于符號整數,有理數,浮點數計算。
第一步: 解壓
[root@deng tmp]# tar -xjvf gmp-5.0.5.tar.bz2
第二步: 檢查環境,生成對應文件
[root@deng tmp]# cd gmp-5.0.5
[root@deng gmp-5.0.5]# ./configure
第三步: 編譯
[root@deng gmp-5.0.5]# make -j4
[root@deng gmp-5.0.5]# make check
第四步: 安裝
[root@deng gmp-5.0.5]# make install
04. 安裝mpfr
mpfr主要為提供C/C++多精度浮點運算
第一步: 解壓
[root@deng tmp]# tar -xjvf mpfr-3.0.1.tar.bz2
第二步: 檢查環境
[root@deng tmp]# cd mpfr-3.0.1
[root@deng mpfr-3.0.1]# ./configure –with-gmp-include=/usr/local/include –with-gmp-lib=/usr/local/lib
第三步: 編譯
[root@deng mpfr-3.0.1]# make -j4
[root@deng mpfr-3.0.1]# make check
第四步: 安裝
[root@deng mpfr-3.0.1]# make install
05. 安裝mpc
第一步: 解壓
[root@deng tmp]# tar -xzvf mpc-1.0.1.tar.gz
第二步: 檢查環境
[root@deng tmp]# cd mpc-1.0.1
[root@deng mpc-1.0.1]# ./configure
第三步: 編譯
[root@deng mpc-1.0.1]# make -j4
第四步: 安裝
[root@deng mpc-1.0.1]# make install
第五步: 配置
安裝后,它們的頭文件位于”/usr/local/include”,默認情況下程序可以自動找到該路徑;它們的動態庫位于”/usr/local/lib”,可在環境變量追加該路徑,此處就在當前用戶的環境變量上加上該路徑:
[root@deng tmp]# vim ~/.bash_profile
添加如下內容:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/lib64
使配置生效
[root@deng tmp]# source ~/.bash_profile
06. 安裝gcc
第一步: 解壓
[root@deng tmp]# tar -xzvf gcc-4.8.5.tar.gz
第二步: 檢查環境
[root@deng tmp]# cd gcc-4.8.5
[root@deng gcc-4.8.5]# mkdir gcc-4.8.5-build
[root@deng gcc-4.8.5]# cd gcc-4.8.5-build/
可以參考gcc -v選項 注意: 如果此處出現關于java的錯誤, 可以將Java選項去掉
[root@deng gcc-4.8.5-build]# ../configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –disable-multilib –enable-bootstrap –enable-shared –enable-threads=posix –enable-checking=release –with-system-zlib –enable-__cxa_atexit –disable-libunwind-exceptions –enable-gnu-unique-object –enable-languages=c,c++, –disable-dssi –disable-libjava-multilib –with-ppl –with-cloog –with-tune=generic –with-arch_32=i686 –build=x86_64-redhat-linux
第三步: 編譯
[root@deng gcc-4.8.5-build]# make -j4
第四步: 安裝
[root@deng gcc-4.8.5-build]# make install
第五步: 測試
gcc測試
g++測試
驗證安裝
除了可以通過”gcc -v”查看安裝后的gcc版本,還可以通過編寫C++11標準的程序來驗證,在編譯C++11程序時,應該加上”std=c++11”,否則默認是以C99進行編譯,將會拋出錯誤。
07. 錯誤排查(可選 )
如果06出現老版本 就可以參考一下操作
安裝完成后,系統默認沒有修改環境變量,目前還是使用老版本的gcc。
設置使用新版gcc:
ls /usr/local/bin | grep gcc 添加新GCC到可選項,倒數第三個是名字,倒數第二個參數為新GCC路徑,最后一個參數40為優先級,設大一些之后就自動使用新版了
update-alternatives –install /usr/bin/gcc gcc /usr/local/gcc4.8/bin/i686-pc-linux-gnu-gcc 40
第二種方式: 創建軟連接
mkdir /usr/gcc447backup/
mv /usr/bin/{gcc,g++} /usr/gcc447backup
ln -s /usr/local/gcc4.8/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc4.8/bin/g++ /usr/bin/g++
參考博客:https://blog.csdn.net/zlarm/article/details/70255249
參考博客:https://blog.csdn.net/qq_22790049/article/details/52873915
總結
以上是生活随笔為你收集整理的【Tools】gcc4.4升级到gcc4.8的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Tools】Visual Studio
- 下一篇: 【Qt】Qt5.9连接MySQl5.7(