centos 源码编译安装gcc 4.7.0

官方参考:

http://gcc.gnu.org/wiki/InstallingGCC


GCC tends to have problems when configured in the same directory as the GCC source code, or in any subdirectory therein, as stated in the Configuration page in the install documentation.

What should be done is to untar the GCC source code, then in the source directory run ./contrib/download_prerequisites (which will download and untar MPFR, MPC and GMP in the same GCC source code directory as per the prerequisites documentation.)

Then make a peer gcc-build directory next to the GCC source code directory.

Then run the configure either by fully qualified path or by relative path while in the the gcc-build current working directory.

A makefile will be created in the gcc-build directory. Run make in the gcc-build current working directory to begin the build of GCC.

(If building a cross-compiler, there are several more prerequisite steps involved.)

The above steps are atypical of most GNU packages. GCC builds in multiple passes; which, if done within the GCC source code directory, befouls the source code directory itself. Hence the need to build in a separate build directory.

MPFR, MPC and GMP are used by GCC itself, internally. GCC does not use those facilities in the code compiled by GCC.


转载的下文有大量错误,不要尝试。

gcc官方网站 下载最新版本的gcc-4.7.0.tar.bz2
同时在infrastructure目录下寻找下载【必须】的cloog-0.16.2.tar.gz、mpc-0.8.1.tar.gz、mpfr-2.4.2.tar.bz2、ppl-0.11.tar.gz,去http://gmplib.org/ 下载最新的gmp-5.0.4.tar.bz2
开始前的注意事项:
【我是在CentOS 5.3 x64的虚拟机环境下实践的此文,推荐内存要大于2G,否则在编译一些模块时会出现因为物理内存耗光而死机的情况】

开始安装gcc 4.7.0,以下包的安装步骤不能错乱

? View Code TEXT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
tar jxvf gmp-5.0.4.tar.bz2
cd gmp-5.0.4
./configure --prefix=/usr/local/gmp-5.0.4
make && make install
cd ../
 
tar jxvf mpfr-2.4.2.tar.bz2
cd mpfr-2.4.2
./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-5.0.4
make && make install
cd ../
 
tar zxvf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --prefix=/usr/local/mpc-0.8.1  --with-gmp=/usr/local/gmp-5.0.4 --with-mpfr=/usr/local/mpfr-2.4.2
make && make install
cd ../

由于cloog-0.16.2是【isl-based version】,在gcc的./configure 时,使用–enable-cloog-backend=isl参数来指定cloog的后端为isl即可

? View Code TEXT
1
2
3
4
5
6
7
8
9
10
11
tar zxvf ppl-0.11.tar.gz
cd ppl-0.11
./configure --prefix=/usr/local/pp1-0.11 --with-gmp=/usr/local/gmp-5.0.4
make && make install
cd ../
 
tar zxvf cloog-0.16.2.tar.gz
cd cloog-0.16.2
./configure --prefix=/usr/local/cloog-0.16.2 --with-gmp=/usr/local/gmp-5.0.4
make && make install
cd ../

安装gcc 4.7.0,此处的参数,只针对C、C++语言,如果需要其能编译出其他工具链(如all, ada, fortran, go, java, objc, obj-c++之类的),在enable-language后面添加上,然后添加上相应的参数就是

? View Code TEXT
1
2
3
4
tar jxvf gcc-4.7.0.tar.bz2
cd gcc-4.7.0
./configure --with-gmp=/usr/local/gmp-5.0.4 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1 --enable-languages=c,c++ --enable-threads=posix --enable-__cxa_atexit --with-cpu=generic --disable-multilib --with-ppl=/usr/local/pp1-0.11 --with-cloog=/usr/local/cloog-0.16.2 --enable-cloog-backend=isl
make && make install

将以上四个库加入系统库路径,使用在/etc/ld.so.conf中添加或LD_LIBRARY_PATH环境变量中添加的方式
如在~/.bashrc中添加上下面语句

? View Code TEXT
1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp-5.0.4/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/mpc-0.8.1/lib:/usr/local/cloog-0.16.2/lib:/usr/local/ppl-0.11/lib
使用gcc -v即可查看到新安装的gcc版本已经变为4.7.0了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值