標籤:gcc 下載 編譯 依賴
最新的gcc-5.1.0才發布出來,迫不及待地裝上試一試。
在http://ftp.gnu.org/gnu/gcc/下載gcc-5.1.0
然後解壓到目錄gcc-5.1.0/
運行
./contrib/download_prerequisites
下載編譯所需的依賴包
gcc依賴包有:m4-1.4.17.tar.gz,gmp-5.1.3.tar.gz mpfr-3.1.2.tar.gz mpc-1.0.3.tar.gz
但是這些包都太新了,這些依賴包太新了也不行,太舊了也不行,只能使用合適的版本,這樣使用gcc內建的下載依賴的方式最好不過了。
然後在gcc-5.1.0/ 的同一級目錄下面
mkdir gcc-build/cd gcc-build../gcc-5.1.0/configure --build=x86_64-linux-gnu --prefix=/usr/local/lib/gcc-5.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib
執行完configure之後產生了Makefile檔案,然後:
make
如果你的電腦有4核CPU的話可以直接make -j4
make install
好啦,現在在你的/usr/local/lib/下有個gcc-5.1.0的目錄了,這個目錄就是gcc-5.1.0的安裝目錄。只要把/usr/local/lib/gcc-5.1.0/bin加入到PATH中就行了。
如果嫌上述安裝步驟太繁瑣就直接使用我寫的指令碼:
github上的gcc-install.sh指令碼
如果指令碼下載gcc-5.1.0很慢的話(被牆了),那麼可以先下載gcc-5.1.0.tar.gz到指令碼同一層級目錄,然後執行指令碼
我們來看看依賴庫如果太新會怎麼樣:
以下是錯誤的安裝方法:—————————————-
先下載m4-1.4.17.tar.gz,gmp-5.1.3.tar.gz mpfr-3.1.2.tar.gz mpc-1.0.3.tar.gz
全部解壓到/root目錄下然後:
安裝m4:——————————-
cd m4-1.4.17./configure --prefix=/usr/local/lib/m4-1.4.17make make checkmake install
安裝gmp:————————————
cd gmp-5.1.3./configure --prefix=/usr/local/lib/gmp-5.1.3makemake checkmake install
安裝mpfr:———————————————
cd mpfr-3.1.2./configure --prefix=/usr/local/lib/mpfr-3.1.2 --with-gmp=/usr/local/lib/gmp-5.1.2makemake checkmake clean
安裝mpc:———————————————-
cd mpc-1.0.3./configure --prefix=/usr/local/lib/mpc-1.0.3 --with-gmp=/usr/local/lib/gmp-5.1.3 --with-mpfr=/usr/local/lib/mpfr-3.1.2makemake checkmake install
安裝gcc:———————————————————-
cd gcc-build/../gcc-5.1.0/configure --build=x86_64-linux-gnu --prefix=/usr/local/lib/gcc-5.1.0 --with-gmp=/usr/local/lib/gmp-5.1.3 --with-mpfr=/usr/local/lib/mpfr-3.1.2 --with-mpc=/usr/local/lib/mpc-1.0.3 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilibmake -j4
出錯了:
configure: error: in `/root/gcc-5.1.0/x86_64-unknown-linux-gnu/libgcc’: configure: error: cannot compute suffix of object files: cannot compile
前功盡棄,還是老老實實按照前面的方法安裝吧
linux編譯gcc-5.1.0