【Tools】gcc4.4升级到gcc4.8
00.目錄
- 00.目錄
- 01. 簡(jiǎn)介
- 02. 軟件包下載
- 03. 安裝gmp
- 04. 安裝mpfr
- 05. 安裝mpc
- 06. 安裝gcc
- 07. 錯(cuò)誤排查(可選 )
01. 簡(jiǎn)介
由于gcc4.4不支持C++11新特性,所以將Redhat6.5中g(shù)cc4.4升級(jí)到gcc4.8. 本文介紹在系統(tǒng)無(wú)法連接互聯(lián)網(wǎng)的情況下,如何升級(jí)GCC。離線和在線升級(jí)的主要區(qū)別在于,如果可以聯(lián)網(wǎng),在升級(jí)gcc前的需要安裝的依賴包,可以通過(guò)運(yùn)行g(shù)cc安裝包下的腳本自行下載安裝,免去了很多的麻煩。
環(huán)境:RedHat6.5
首先下載gcc安裝包,本文為gcc-4.8.5.tar.gz,解壓后,如果直接運(yùn)行安裝目錄下的configure腳本,可能會(huì)因?yàn)楫?dāng)前系統(tǒng)的GMP,MPFR,MPC的版本過(guò)低而拋出如下的錯(cuò)誤
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.
如果是在聯(lián)網(wǎng)環(huán)境,可以運(yùn)行安裝目錄下的”./contrib/download_prerequisites”腳本來(lái)下載相關(guān)的依賴。而由于我們是在局域網(wǎng)內(nèi),所以需要到因特網(wǎng)中下載這三個(gè)安裝包,然后逐個(gè)安裝:
download_prerequisites腳本內(nèi)容如下:
#! /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是一個(gè)任意精度的開(kāi)源算術(shù)庫(kù),可用于符號(hào)整數(shù),有理數(shù),浮點(diǎn)數(shù)計(jì)算。
第一步: 解壓
[root@deng tmp]# tar -xjvf gmp-5.0.5.tar.bz2
第二步: 檢查環(huán)境,生成對(duì)應(yīng)文件
[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++多精度浮點(diǎn)運(yùn)算
第一步: 解壓
[root@deng tmp]# tar -xjvf mpfr-3.0.1.tar.bz2
第二步: 檢查環(huán)境
[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
第二步: 檢查環(huán)境
[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”,默認(rèn)情況下程序可以自動(dòng)找到該路徑;它們的動(dòng)態(tài)庫(kù)位于”/usr/local/lib”,可在環(huán)境變量追加該路徑,此處就在當(dāng)前用戶的環(huán)境變量上加上該路徑:
[root@deng tmp]# vim ~/.bash_profile
添加如下內(nèi)容:
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
第二步: 檢查環(huán)境
[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選項(xiàng) 注意: 如果此處出現(xiàn)關(guān)于java的錯(cuò)誤, 可以將Java選項(xiàng)去掉
[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
第五步: 測(cè)試
gcc測(cè)試
g++測(cè)試
驗(yàn)證安裝
除了可以通過(guò)”gcc -v”查看安裝后的gcc版本,還可以通過(guò)編寫(xiě)C++11標(biāo)準(zhǔn)的程序來(lái)驗(yàn)證,在編譯C++11程序時(shí),應(yīng)該加上”std=c++11”,否則默認(rèn)是以C99進(jìn)行編譯,將會(huì)拋出錯(cuò)誤。
07. 錯(cuò)誤排查(可選 )
如果06出現(xiàn)老版本 就可以參考一下操作
安裝完成后,系統(tǒng)默認(rèn)沒(méi)有修改環(huán)境變量,目前還是使用老版本的gcc。
設(shè)置使用新版gcc:
ls /usr/local/bin | grep gcc 添加新GCC到可選項(xiàng),倒數(shù)第三個(gè)是名字,倒數(shù)第二個(gè)參數(shù)為新GCC路徑,最后一個(gè)參數(shù)40為優(yōu)先級(jí),設(shè)大一些之后就自動(dòng)使用新版了
update-alternatives –install /usr/bin/gcc gcc /usr/local/gcc4.8/bin/i686-pc-linux-gnu-gcc 40
第二種方式: 創(chuàng)建軟連接
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
總結(jié)
以上是生活随笔為你收集整理的【Tools】gcc4.4升级到gcc4.8的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Tools】Visual Studio
- 下一篇: 【Qt】Qt5.9连接MySQl5.7(