Linux下源码编译安装GCC5.3.0
系统环境:Amazon Linux AMI 2015.09.2 (HVM)— 23 Server
1、下载gcc-5.3.0安装包并将gcc-5.3.0.tar.gz放到/opt目录下解压:
#sudo su
#mkdir /opt/&cd /opt/
#wget https://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这三个库,可从下载相应的压缩包。由于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下Vim+GCC+GDB安装及使用
Ubuntu下两个GCC版本切换
GCC 的详细介绍:
转载自:https://www.linuxidc.com/Linux/2016-03/128965.htm
声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 嗅谱网
转载请注明:转自《Linux下源码编译安装GCC5.3.0》
本文地址:http://www.xiupu.net/archives-6123.html
关注公众号:
微信赞赏
支付宝赞赏