从源代码编译、安装gcc

从源代码编译、安装gcc
参考:
http://www.comdyn.cn/from-web/68-server-setup/164-centos-48-gcc450.html


我的环境:CentOS 6.2, kernel 3.1.10  x86_64
需要的配置:Disk space >= 6GB, Mem >= 1GB

从gcc.gnu.org下载gcc-4.7.2.tar.bz2,创建/root/buid-gcc目录,以后所有编译都在这个目录里进行了。
ftp://gcc.gnu.org/pub/gcc/infrastructure/处下载以下辅助安装包: gmp-4.3.2.tar.bz2, mpfr-2.4.2.tar.bz2, mpc-0.8.1.tar.gz

将以上bz2和gz ball全部放到/root/build-gcc目录下。

1. 编译gmp-4.3.2
展开gmp-4.3.2.tar.bz2:
#tar xf gmp-4.3.2.tar.bz2
# mkdir gmp-build
#cd gmp-build
#../gmp-4.3.2/configure --prefix=/root/rpmbuild/gmp-build 
--build=x86_64-linux
注意:
--build=x86_64-linux选项对于x86_64的平台(比如我用的这个系统)非常重要,否则,无法生成Makefile。
生成Makefile以后,用以下命令编译:
#make
#make check
#make install
这样就把gmp安装到了
/root/build-gcc/gmp-build目录,gmp的安装就完成了,/root/build-gcc/gmp-build目录在将来安装其他包的时候会作为参数被传递。

2. 编译mpfr
#tar xf mpfr-2.4.2.tar.bz2
#mkdir mpfr-build
#cd mpfr-build
#
../mpfr-2.4.2/configure --prefix=/root/build-gcc/mpfr-build/ --with-gmp=/root/build-gcc/gmp-build
#make
#make check
#make install

3.编译mpc
#tar xf mpc-0.8.1.tar.gz
#mkdir mpc-build
#cd mpc-build
#../mpc-0.8.1/configure --prefix=/root/build-gcc/mpc-build/ --with-gmp=/root/build-gcc/gmp-build/ --with-mpfr=/root/build-gcc/mpfr-build/
#make; make check; make install

4.编译GCC
#tar xf gcc-4.7.2.tar.bz2
#mkdir gcc-build
设置LD_LIBRARY_PATH (可选)
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/build-gcc/mpc-build/lib:/root/build-gcc/mpfr-build/lib:/root/build-gcc/gmp-build/lib
创建makefile
#../gcc-4.7.2/configure --prefix=/root/build-gcc/gcc-build/ --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/root/build-gcc/gmp-build/ --with-mpfr=/root/build-gcc/mpfr-build/ --with-mpc=/root/build-gcc/mpc-build/

Build过程中可能出现的错误:
有些包没装(虽然之前已经通过命令#
yum groupinstall "Development Tools" 安装了 "Development Tools") ,比如ppl和ppl-devel,可能会出现错误:configure: error: cannot compute suffix of object files: cannot compile。查看日志发现错误记录:
conftest.c:10:19: error: ppl_c.h: No such file or directory
conftest.c:16: error: 'choke' undeclared (first use in this function)
conftest.c:16: error: (Each undeclared identifier is reported only once
conftest.c:16: error: for each function it appears in.)
conftest.c:16: error: expected ';' before 'me'
这些错误可以通过命令:
#yum install ppl ppl-devel
安装这两个包来改正。

另外,如果严谨一点, make完后应该要做make -k check的,但是make -k check会报告缺少autogen这个命令,可问题在于 CentOS里很难找到这个autogen,所以,马虎点好了,make完后直接make install。

make install完成后,将会在/root/build-gcc/gcc-build/bin目录下生成最终的可执行文件,如gcc,g++这些。而这时,
/root/build-gcc/gcc-build/bin并不存在于PATH中。这就需要将新生成的gcc放到/usr/bin中,让其“可用”了:
#ln -s /root/build-gcc/gcc-build/bin/gcc /usr/bin/gcc-4.7
#ln -s /root/build-gcc/gcc-build/bin/g++ /usr/bin/g++-4.7
注意:以上必须用绝对路径!

其后就可以用gcc-4.7和g++-4.7命令编程序了 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值