歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 6.5下源碼安裝GCC-4.8.2安裝筆記整理

CentOS 6.5下源碼安裝GCC-4.8.2安裝筆記整理

日期:2017/2/28 14:33:13   编辑:Linux教程

經歷了兩天的虐心,寫了兩篇不敢發表的gcc4.8.2安裝筆記,終於成功用源碼安裝最新的gcc-4.8.2,雖然最初只是為了試一試c++11的幾個性能,但是後來不斷遇到的問題和搜索中發現的這些問題在大家安裝過程中的普遍存在,決心把它寫下來和大家共享,鄙人也是個菜鳥,有什麼說的不對的地方希望大家予以指正,不勝感激:

首先,個人經歷了不斷地失敗之後,認為官方的安裝指導文檔甚為重要,如果一開始能夠 認真閱讀,或許就不會花費這麼久,好多問題也就不會出現,官方文檔鏈接為http://gcc.gnu.org/install/

相關資源下載地址為ftp://gnu.mirror.iweb.com/ 和 ftp://gcc.gnu.org/pub/gcc/infrastructure/

推薦閱讀:

Ubuntu 12.04嵌入式交叉編譯環境arm-linux-GCC搭建過程圖解 http://www.linuxidc.com/Linux/2013-06/85902.htm

Ubuntu 12.10安裝交叉編譯器arm-none-linux-gnueabi-GCC http://www.linuxidc.com/Linux/2013-03/82016.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



下面開始介紹個人總結的認為較好的安裝順序,望大家予以點評:

• 根據官方文檔Prerequisites的要求,安裝GNAT,texinfo,因為GANT依賴於texinfo,texinfo直接yum就行,版本夠用,GNAT源碼安裝
•安裝isl和cloog,下載源碼安裝包,可以直接安裝,gcc可以找到,也可以在安裝gcc是接下到gcc的源碼目錄下,並建立軟連接,對於第二種情況官方文檔中有詳細說明,而且建議那樣做,當時沒注意,導致在用戶目錄下編譯找不到isl
•autoconf本機版本過低,源碼重新安裝
•gettext本機顯示未安裝,yum即可,基於依賴,自動安裝兩個包: cvs-1.11.23-16.el6.i686.rpm gettext-0.17-16.el6.i686.rpm
•gperf顯示未安裝,繼續yum 。安裝:gperf.i686 0:3.0.3-9.1.el6
•dejagnu,繼續yum
•安裝TCL:wget http://cznic.dl.sourceforge.net/project/tcl/Tcl/8.6.1/tcl861-src.zip
解壓進入unix文件夾,configure,make ,make test,make install
•安裝guile(同時安裝guile-devel,autogen依賴於此庫)sudo yum install guile*
•然後安裝autogen
•flex:ftp上沒有資源,裡面Readme文件提示源碼位置:

wget http://jaist.dl.sourceforge.net/project/flex/flex-2.5.39.tar.gz

執行到make check報錯:

Executing test test-bison-yylloc

Test test-bison-yylloc FAILED. See test-bison-yylloc/OUTPUT for details.

Executing test test-bison-yylval

Test test-bison-yylval FAILED. See test-bison-yylval/OUTPUT for details.

Executing test test-bison-nr

Test test-bison-nr FAILED. See test-bison-nr/OUTPUT for details.

執行sudo yum install bison*

安裝:

bison-2.4.1-5.el6.i686.rpm

bison-devel-2.4.1-5.el6.i686.rpm

bison-runtime-2.4.1-5.el6.i686.rpm

•安裝TeX:

官方網址:https://tug.org/

下載:wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

官方安裝指導:https://tug.org/texlive/quickinstall.html

cd /your/download/directory

./install-tl

[... messages omitted ...]

Enter command: i

[... when done, see below for post-install ...]

這個過程特別漫長,如果網速快的話另論,不過感覺應該是資源問題

後來改用鏡像安裝,鏡像下載地址(http://mirrors.ustc.edu.cn/CTAN/systems/texlive/Images/texlive2013.iso)

使用鏡像安裝過程很快,具體安裝步驟相同,安裝完成顯示:

See

/usr/local/texlive/2013/index.html

for links to documentation. The TeX Live web site

contains updates and corrections: http://tug.org/texlive.

TeX Live is a joint project of the TeX user groups around the world;

please consider supporting it by joining the group best for you. The

list of user groups is on the web at http://tug.org/usergroups.html.


Add /usr/local/texlive/2013/texmf-dist/doc/man to MANPATH, if not dynamically found.

Add /usr/local/texlive/2013/texmf-dist/doc/info to INFOPATH.

Most importantly, add /usr/local/texlive/2013/bin/i386-linux

to your PATH for current and future sessions.

Welcome to TeX Live!

Logfile: /usr/local/texlive/2013/install-tl.log

After the installation finishes, you must add the directory of TeX Live binaries to your PATH—except on Windows, where the installer takes care of this. For example:

PATH=/usr/local/texlive/2013/bin/i386-linux:$PATH

Use the syntax for your shell, your installation directory, and your binary platform name instead of i386-linux.

修改環境變量,包括以上三條加粗表示部分,source,安裝成功

•安裝SVN:

直接yum,安裝:

perl-URI-1.40-2.el6.noarch.rpm

subversion-1.6.11-10.el6_5.i686.rpm


•我的binutils先前剛剛用源碼更新過,大家如果需要可以根據官方文檔http://gcc.gnu.org/install/download.html 的說明進行更新

下面進入正式安裝:

切換到root用戶(先前使用sudo總是提示找不到工具,可能是沒有讀進換進變量,也可能是在用戶目錄下進行編譯的問題),先前弄得有點亂,依賴問題全部解決後還是有configure: error: source directory already configured; run "make distclean" there first這樣的報錯,但是,make distclean執行不成功,後來干脆就不在用戶目錄下進行了

切換至/opt目錄(用戶目錄下連flex都找不到),解壓gcc源碼包到這個目錄

tar xzvf gcc-4.8.2.tar.gz

cd gcc-4.8.2

./contrib/download_prerequisites (執行這個腳本自動下載並關聯GMP,MPFR和MPC,不然會產生一系列報錯諸如:

1、cannot find the library `../libgmp.la' or unhandled argument `../libgmp.la'

2、checking for suffix of object files... configure: error: in `/home/Oracle/Downloads/gcc-4.8.2/i686-pc-linux-gnu/libgcc':

configure: error: cannot compute suffix of object files: cannot compile

See `config.log' for more details.,查看日志提示找不到libmpc.so.2,可是他明明就在那裡,還是讓gcc自己編譯吧

3、而且這麼干連分別安裝時安裝MPFR的 gmp.h version and libgmp version are the same... (4.3.2/4.3.1) no報錯都解決了,當然,如果特別想分別安裝,這個錯誤可以在MPFR配置是使用./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib予以解決,分別安裝好以後按照文檔要求進行confiugure)

./contrib/download_ecj (這樣就不用安裝ecj了,畢竟用不了那麼多東西,真要想裝的話yum就行)

cd ..

mkdir objdir(據說不能再源碼目錄下編譯,否則會出現configure: error: source directory already configured; run "make distclean" there first,我 沒有試過)

cd objdir

../gcc-4.8.2/configure (沒有設置prefix啥的,我這裡沒必要,大家需要的話可以設置)

make(差不多一個半小時,慢的一B)

make install (搞定)

測試一下看是不是成功

直接輸入gcc --version

顯示版本是4.8.2,成功

總結下來,最有用的還是官方文檔和gnu的論壇和bug提交的郵件系統,認真看一下可以少走好多彎路,個人能力有限,歡迎大家指正或者補充,感激不盡。

GCC 的詳細介紹:請點這裡
GCC 的下載地址:請點這裡

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

Copyright © Linux教程網 All Rights Reserved