安裝的redhat版本
[[email protected] ~]$ lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Release: 5.4
Codename: Tikanga
1.下載下傳gcc-4.6.1安裝包
gcc各版本浏覽位址:http://ftp.gnu.org/gnu/gcc/
2.将gcc-4.6.1.tar.bz2放到/opt檔案夾下解壓
[[email protected] ~]# cd /opt
[[email protected] opt]# tar -xjvf gcc-4.8.3.tar.bz2
3.建立安裝目錄
[[email protected] opt]# mkdir /usr/local/gcc-4.8.3/
4.進入安裝目錄
[[email protected] opt]# cd /usr/local/gcc-4.8.3/
5.配置安裝檔案
[[email protected] gcc-4.8.3]# /opt/gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3
(執行源目錄 /opt/gcc-4.8.3/中的configure指令,配置将gcc安裝到目标目錄/usr/local/gcc-4.8.3/下,這裡–prefix選項代表要将該庫安裝在哪裡,我是裝在/usr/local/gcc-4.8.3目錄下,後面的安裝都會用到這個選項)
如果執行這步的時候出現了如下錯誤:
----------------------------------------------------------------------------------
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需要GMP、MPFR、MPC這三個庫,可從ftp://gcc.gnu.org/pub/gcc/infrastructure/下載下傳相應的壓縮包。由于MPFR依賴GMP,而MPC依賴GMP和MPFR,是以要先安裝GMP,其次MPFR,最後才是MPC。這裡三個庫我用的版本分别是gmp4.3.2,mpfr2.4.2和mpc0.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- 4.8.3
[ [email protected] gcc- 4.8.3]# /opt/gcc- 4.8.3/configure --prefix=/usr/local/gcc- 4.8.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] gcc-4.8.3]# make
大概需要1個小時左右
第二個錯誤出現了:
打開/usr/local/gcc-4.8.3/i686-pc-linux-gnu/libgcc/config.log
ctrl+f查找error 發現如下錯誤
/----------------------------------------------------------------------------------
/usr/local/gcc-4.8.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] gcc-4.8.3]# export LD_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] gcc-4.8.3]# make install
[[email protected] gcc-4.8.3]#
如果不出意外,那麼到現在應該安裝成功了,不過還是不能使用新版本的gcc,因為新版本的gcc還沒有加入指令搜尋路徑中!
8.建立軟連結
[[email protected] /]# sudo ln -s /usr/local/gcc-4.8.3/bin/gcc gcc48
[[email protected] /]# sudo ln -s /usr/local/gcc-4.8.3/bin/g++ g++48
9.添加環境變量
[root@localhost linfeng]# export PATH=$PATH:/usr/local/gcc-4.8.3/bin/