最新版本gcc5.3安裝詳解

1.下載gcc-5.3安裝包
gcc各版本瀏覽地址:http://ftp.gnu.org/gnu/gcc/
gcc-5.3
瀏覽地址:http://ftp.gnu.org/gnu/gcc/gcc-5.3/
gcc-5.3下載地址:http://ftp.gnu.org/gnu/gcc/gcc-5.3/gcc-5.3.tar.bz2
2.
將gcc-5.3.tar.bz2放到/opt文件夾下解壓
[[email protected] ~]# cd /opt
[[email protected]]# tar xjvf gcc-5.3.tar.bz2
3.
創建安裝目錄
[[email protected]]# mkdir /usr/local/gcc-5.3/
4.
進入安裝目錄
[[email protected]]# cd /usr/local/gcc-5.3/
5.
配置安裝文件
[[email protected]]# /opt/gcc-5.3/configure --prefix=/usr/local/gcc-5.3
(
執行源目錄 /opt/gcc-5.3/中的configure命令,配置將gcc安裝到目標目錄/usr/local/gcc-5.3/下,這裏–prefix選項代表要將該庫安裝在哪裏,我是裝在/usr/local/gcc-5.3目錄下,後面的安裝都會用到這個選項)

如果執行這步的時候出現瞭如下錯誤:
----------------------------------------------------------------------------------
[[email protected] gcc-5.3]# /opt/gcc-5.3/configure --prefix=/usr/local/gcc-5.3/
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking target system type… i686-pc-linux-gnu
checking for a BSD-compatible install… /usr/bin/install -c
checking whether ln works… yes
checking whether ln -s works… yes
checking for a sed that does not truncate output… /bin/sed
checking for gawk… gawk
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in`/usr/local/gcc-5.3':
configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details.
----------------------------------------------------------------------------------
上面錯誤說明$PATH裏沒有找到C的編譯器
如果系統有gcc編譯器,那就設置下環境變量
比如:
export PATH=$PATH:/usr/local/bin
如果沒有找到那麼先安裝gcc低版本的rpm
插入linux軟件盤(一般在第一張或第二張),掛載光盤,按下面順序依次安裝:

[[email protected] opt]# rpm -ivhcpp-4.1.2-48.el5.i386.rpm
[[email protected] opt]# rpm -ivhkernel-headers-2.6.18-194.el5.i386.rpm
[[email protected] opt]# rpm -ivhglibc-headers-2.5-49.i386.rpm
[[email protected] opt]# rpm -ivhglibc-devel-2.5-49.i386.rpm
[[email protected] opt]# rpm -ivhlibgomp-4.4.0-6.el5.i386.rpm
[[email protected] opt]# rpm -ivhgcc-4.1.2-48.el5.i386.rpm

重複步驟5,又有新錯誤了,下面是部分錯誤代碼!如果沒有錯誤,直接跳到步驟7 !
----------------------------------------------------------------------------------
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.
----------------------------------------------------------------------------------

錯誤說明要安裝gcc需要GMPMPFRMPC這三個庫,可從ftp://gcc.gnu.org/pub/gcc/infrastructure/下載相應的壓縮包。由於MPFR依賴GMP,而MPC依賴GMPMPFR,所以要先安裝GMP,其次MPFR,最後纔是MPC。這裏三個庫我用的版本分別是gmp4.3.2mpfr2.4.2mpc0.8.1,都放在 /opt文件夾下。
.安裝gmp4.3.2
[[email protected] opt]# tar jxvf gmp-4.3.2.tar.bz2
[[email protected] opt]# mkdir /usr/local/gmp-4.3.2
[[email protected] opt]# cd /usr/local/gmp-4.3.2
[[email protected] gmp-4.3.2]# 
/opt/gmp-4.3.2/configure --prefix=/usr/local/gmp-4.3.2
[[email protected] gmp-4.3.2]# make
(編譯)
[[email protected] gmp-4.3.2]# make install
(執行安裝)
安裝mpfr2.4.2
[[email protected] opt]# tar jxvf mpfr2.4.2.tar.bz2
[[email protected] opt]# mkdir /usr/local/mpfr-2.4.2
[[email protected] opt]# cd /usr/local/mpfr-2.4.2
[[email protected] mpfr-2.4.2]# 
/opt/mpfr-2.4.2/configure --prefix=/usr/local/mpfr-2.4.2--with-gmp=/usr/local/gmp-4.3.2
(注意配置的時候要把依賴關係選項加進去)
[[email protected] mpfr-2.4.2]# make
[[email protected] mpfr-2.4.2]# make install
安裝mpc0.8.1
[[email protected] opt]# tar jxvf gmpc0.8.1.tar.bz2
[[email protected] opt]# mkdir /usr/local/mpc-0.8.1
[[email protected] opt]# cd /usr/local/mpc-0.8.1
[[email protected] mpc-0.8.1]# 
/opt/mpc-0.8.1/configure --prefix=/usr/local/mpc-0.8.1--with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2
[[email protected] mpc-0.8.1]# make
[[email protected] mpc-0.8.1]# make install
再次安裝GCC 配置安裝選項
[[email protected] mpc-0.8.1]# cd /usr/local/gcc-5.3
[[email protected] gcc-5.3]# 
/opt/gcc-5.3/configure --prefix=/usr/local/gcc-5.3 -enable-threads=posix-disable-checking -disable-multilib -enable-languages=c,c++--with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2--with-mpc=/usr/local/mpc-0.8.1

6.編譯安裝文件
[[email protected]]# make
大概需要1個小時左右,喝杯coffee,慢慢等待吧!
一個小時後···
第二個錯誤出現了:

打開/usr/local/gcc-5.3/i686-pc-linux-gnu/libgcc/config.log
ctrl+f
查找error 發現如下錯誤
/----------------------------------------------------------------------------------
/usr/local/gcc-5.3/./gcc/cc1: error while loading shared libraries:libmpc.so.2: cannot open shared object file: No such file or directory
configure:3058: $? = 1
----------------------------------------------------------------------------------/
在網上找到了解決方法,需要添加環境變量LD_LIBRARY_PATH以指出前面三個庫的位置,鍵入以下命令:
[[email protected]]# exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib
再次執行步驟6→
大概三小時後···
終於編譯成功了,效果圖入下:

7.執行安裝gcc
[[email protected]]# make install
[[email protected] gcc-5.3]# 
如果不出意外,那麼到現在應該安裝成功了,不過還是不能使用新版本的gcc,因爲新版本的gcc還沒有加入命令搜索路徑中!
8.建立軟鏈接
[[email protected]/]# sudoln -s /usr/local/gcc-5.3/bin/gcc gcc461
[[email protected] /]# sudo ln -s /usr/local/gcc-5.3/bin/g++ g++461
9.
添加環境變量 
打開/etc目錄下的bashrc文件添加如下代碼:
LD_LIBRARY_PATH=:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-5.3/lib

exportLD_LIBRARY_PATH
發佈了138 篇原創文章 · 獲贊 29 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章