歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下源碼編譯安裝GCC5.3.0

Linux下源碼編譯安裝GCC5.3.0

日期:2017/2/28 13:54:12   编辑:Linux教程

系統環境:Amazon Linux AMI 2015.09.2 (HVM)---Fedora 23 Server

1、下載gcc-5.3.0安裝包並將gcc-5.3.0.tar.gz放到/opt目錄下解壓:

#sudo su

#mkdir /opt/&cd /opt/

#wget http://ftp.gnu.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz

#tar –zxf gcc-5.3.0.tar.gz

2、創建安裝目錄:

#mkdir /usr/local/gcc-5.3.0/

#cd /usr/local/gcc-5.3.0/

3、配置安裝文件:

#/opt/gcc-5.3.0/configure –prefix=/usr/local/gcc-5.3.0

如果執行時出現如下報錯:

-----------------------------------------------------------------------

configure: error: in `/usr/local/gcc-5.3.0':
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包

安裝順序:cpp-kernel--->headers--->glibc--->headers--->glibc--->devel--->libgomp--->gcc

重復步驟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

#tar jxvf gmp-4.3.2.tar.bz2

#mkdir /usr/local/gmp-4.3.2

#cd /usr/local/gmp-4.3.2

#/opt/gmp-4.3.2/configure –prefix=/usr/local/gmp-4.3.2

#make

make install

②安裝mpfr2.4.2

#tar jxvf mpfr-2.4.2.tar.bz2

#mkdir /usr/local/mpfr-2.4.2

#cd /usr/local/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
#make

#make install

③安裝mpc0.8.1

#tar –zxf mpc-0.8.1.tar.gz

#mkdir /usr/local/mpc-0.8.1

#cd /usr/local/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

#make

#make install

④再次安裝GCC 配置安裝選項

#cd /usr/local/gcc-5.3.0

#/opt/gcc-5.3.0/configure --prefix=/usr/local/gcc-5.3.0 -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

4、編譯安裝文件

#make

再次報錯:

/usr/local/gcc-5.3.0/./prev-gcc/cc1plus: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
make[3]: *** [real.o] Error 1
make[3]: Leaving directory `/usr/local/gcc-5.3.0/gcc'
make[2]: *** [all-stage3-gcc] Error 2
make[2]: Leaving directory `/usr/local/gcc-5.3.0'
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/usr/local/gcc-5.3.0'
make: *** [all] Error 2
分析:/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libgcc/config.log

查找下error會發現很多錯誤,大部分是庫沒找到。

#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

#make

大概30 min後···
終於編譯成功了。

libtool: link: ranlib .libs/libatomic.a
libtool: link: ( cd ".libs" && rm -f "libatomic.la" && ln -s "../libatomic.la" "libatomic.la" )
true DO=all multi-do # make
make[4]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/usr/local/gcc-5.3.0'

5、執行安裝gcc:

#make install

6、將新版本的gcc加入命令搜索路徑中:

#ln -s /usr/local/gcc-5.3.0/bin/gcc gcc
#ln -s /usr/local/gcc-5.3.0/bin/g++ g++

7、添加環境變量:

# vi /etc/bashrc

加入代碼:

添加如下代碼:

# gcc
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-4.6.1/lib

#export LD_LIBRARY_PATH

至此安裝完畢!

Linux升級GCC 4.8.1清晰簡明教程(Ubuntu 12.04 64位版為例) http://www.linuxidc.com/Linux/2014-04/99583.htm

Ubuntu下Vim+GCC+GDB安裝及使用 http://www.linuxidc.com/Linux/2013-01/78159.htm

Ubuntu下兩個GCC版本切換 http://www.linuxidc.com/Linux/2012-10/72284.htm

CentOS6.5升級手動安裝GCC4.8.2 http://www.linuxidc.com/Linux/2015-01/112595.htm

GCC 的詳細介紹:請點這裡

Copyright © Linux教程網 All Rights Reserved