CentOS 6.5下源码安装GCC-4.8.2安装笔记整理


经历了两天的虐心,写了两篇不敢发表的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搭建过程图解

Ubuntu 12.10安装交叉编译器arm-none-linux-gnueabi-GCC

Ubuntu下Vim+GCC+GDB安装及使用

Ubuntu下两个GCC版本切换


 
下面开始介绍个人总结的认为较好的安装顺序,望大家予以点评:

•  根据官方文档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 的下载地址:请点这里

相关内容