感谢支持
我们一直在努力

Linux下源码编译安装GCC5.3.0

系统环境:Amazon Linux AMI 2015.09.2 (HVM)—Fedora 23 Server

1、下载gcc-5.3.0安装包并将gcc-5.3.0.tar.gz放到/opt目录下解压:

#sudo su

#mkdir /opt/&cd /opt/

#wget http://ftp.gnu.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz

#tar –zxf gcc-5.3.0.tar.gz

2、创建安装目录:

#mkdir /usr/local/gcc-5.3.0/

#cd /usr/local/gcc-5.3.0/

3、配置安装文件:

#/opt/gcc-5.3.0/configure –prefix=/usr/local/gcc-5.3.0

如果执行时出现如下报错:

———————————————————————–

configure: error: in `/usr/local/gcc-5.3.0′:
configure: error: no acceptable C compiler found in $PATH

See `config.log’ for more details.

———————————————————————–

说明$PATH里没有找到C的编译器
如果系统有gcc编译器,那就设置下环境变量
比如:
export PATH=$PATH:/usr/local/bin

如果没有找到那么先安装gcc低版本的rpm包

安装顺序:cpp-kernel—>headers—>glibc—>headers—>glibc—>devel—>libgomp—>gcc

重复步骤3,又出现相关报错:

————————————————————————————————-
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the –with-gmp, –with-mpfr and/or –with-mpc options to specify
their locations.

————————————————————————————————-

错误说明:要安装gcc需要GMP、MPFR、MPC这三个库,可从ftp://gcc.gnu.org/pub/gcc/infrastructure/下载相应的压缩包。由于MPFR依赖GMP,而MPC依赖GMP和MPFR,所以要先安装GMP,其次MPFR,最后才是MPC。

①.安装gmp4.3.2

#tar jxvf gmp-4.3.2.tar.bz2

#mkdir /usr/local/gmp-4.3.2

#cd /usr/local/gmp-4.3.2

#/opt/gmp-4.3.2/configure –prefix=/usr/local/gmp-4.3.2

#make

make install

②安装mpfr2.4.2

#tar jxvf mpfr-2.4.2.tar.bz2

#mkdir /usr/local/mpfr-2.4.2

#cd /usr/local/mpfr-2.4.2

#/opt/mpfr-2.4.2/configure –prefix=/usr/local/mpfr-2.4.2 –with-gmp=/usr/local/gmp-4.3.2
#make

#make install

③安装mpc0.8.1

#tar –zxf mpc-0.8.1.tar.gz

#mkdir /usr/local/mpc-0.8.1

#cd /usr/local/mpc-0.8.1

#/opt/mpc-0.8.1/configure –prefix=/usr/local/mpc-0.8.1 –with-gmp=/usr/local/gmp-4.3.2 –with-mpfr=/usr/local/mpfr-2.4.2

#make

#make install

④再次安装GCC 配置安装选项

#cd /usr/local/gcc-5.3.0

#/opt/gcc-5.3.0/configure –prefix=/usr/local/gcc-5.3.0 -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ –with-gmp=/usr/local/gmp-4.3.2 –with-mpfr=/usr/local/mpfr-2.4.2 –with-mpc=/usr/local/mpc-0.8.1

4、编译安装文件

#make

再次报错:

/usr/local/gcc-5.3.0/./prev-gcc/cc1plus: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
make[3]: *** [real.o] Error 1
make[3]: Leaving directory `/usr/local/gcc-5.3.0/gcc’
make[2]: *** [all-stage3-gcc] Error 2
make[2]: Leaving directory `/usr/local/gcc-5.3.0′
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/usr/local/gcc-5.3.0′
make: *** [all] Error 2
分析:/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libgcc/config.log

查找下error会发现很多错误,大部分是库没找到。

#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib

#make

大概30 min后···
终于编译成功了。

libtool: link: ranlib .libs/libatomic.a
libtool: link: ( cd “.libs” && rm -f “libatomic.la” && ln -s “../libatomic.la” “libatomic.la” )
true  DO=all multi-do # make
make[4]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic’
make[3]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic’
make[2]: Leaving directory `/usr/local/gcc-5.3.0/x86_64-unknown-linux-gnu/libatomic’
make[1]: Leaving directory `/usr/local/gcc-5.3.0′

5、执行安装gcc:

#make install

6、将新版本的gcc加入命令搜索路径中:

#ln -s /usr/local/gcc-5.3.0/bin/gcc gcc
#ln -s /usr/local/gcc-5.3.0/bin/g++ g++

7、添加环境变量:

# vi /etc/bashrc

加入代码:

添加如下代码:

# gcc
LD_LIBRARY_PATH=:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-4.6.1/lib

#export LD_LIBRARY_PATH

至此安装完毕!

Linux升级GCC 4.8.1清晰简明教程(Ubuntu 12.04 64位版为例)  http://www.linuxidc.com/Linux/2014-04/99583.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 

CentOS6.5升级手动安装GCC4.8.2  http://www.linuxidc.com/Linux/2015-01/112595.htm 

GCC 的详细介绍:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/128965.htm

赞(0) 打赏
转载请注明出处:服务器评测 » Linux下源码编译安装GCC5.3.0
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏