美文网首页
CentOS 6 编译安装gcc 5.0+

CentOS 6 编译安装gcc 5.0+

作者: 长江十三寨总瓢把子 | 来源:发表于2018-06-15 14:06 被阅读0次

CentOS6.5默认安装的gcc版本是4.4.7,而处于某些软件的编译需求,gcc版本要求在5.0以上,因此只能DIY了。

1. 环境准备

我自己本地配了个CentOS6.5的虚机,配置好yum源(方法参考:https://www.jianshu.com/p/422813bdd34c)。

  • 编译gcc之前,首先需要环境中已经安装一套gcc和g++
yum install gcc
yum install gcc-c++
tar -xzvf gcc-5.1.0.tar.gz
cd gcc-5.1.0

2. 下载依赖

gcc的源码中有个依赖的下载脚本,如果虚机网络可以正常访问外网,可以直接执行脚本

cat ./contrib/download_prerequisites
GRAPHITE_LOOP_OPT=yes

# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
...

首先执行下载脚本,报错,DNS解析有问题

[root@localhost contrib]# ./download_prerequisites 
--2018-06-15 09:59:24--  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
           => “mpfr-2.4.2.tar.bz2”
Resolving gcc.gnu.org... failed: Name or service not known.
wget: unable to resolve host address “gcc.gnu.org”

尝试解决,但是我的虚机是公司内网,无奈只能手动下载依赖的包了

vim /etc/resolv.conf
nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器

下载下来的依赖包放到gcc源码的contrib目录下,然后编辑download_prerequisites脚本,把下载的命令全部注释掉,重新执行一次。

3. 编译安装

第一次编译报错

./configure --prefix=/usr/gcc --enable-languages=c,c++
...
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the   options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

添加--with-gmp --with-mpfr --with-mpc之后再次尝试,报同样的错误,似乎gcc并不会自动编译安装这些依赖包,尝试先手动安装。

3.1 编译安装GMP

cd /opt/gcc-5.1.0/contrib/gmp
./configure --prefix=/usr/gmp-4.3.2
make && make install

3.2 编译安装MPFR

cd /opt/gcc-5.1.0/contrib/mpfr-2.4.2
./configure --prefix=/usr/mpfr-2.4.2 --with-gmp=/usr/gmp-4.3.2
make && make install

3.3 编译安装MPC

cd /opt/gcc-5.1.0/contrib/mpc-0.8.1
./configure --prefix=/usr/mpc-0.8.1 --with-gmp=/usr/gmp-4.3.2 --with-mpfr=/usr/mpfr-2.4.2 
make && make install

然后配置lib环境变量

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

再次尝试编译gcc

./configure --prefix=/usr/gcc --enable-languages=c,c++ --with-gmp=/usr/gmp-4.3.2 --with-mpfr=/usr/mpfr-2.4.2 --with-mpc=/usr/mpc-0.8.1
...
checking for compatible ISL... no
*** This configuration is not supported in the following subdirectories:
     target-libmpx gnattools gotools target-libada target-libgfortran target-libgo target-libffi target-libbacktrace target-zlib target-libjava target-libobjc target-liboffloadmic target-boehm-gc
    (Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... no
/usr/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit developement libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

缺少32位的依赖包,但是我只想编译64位的,因此添加--disable-multilib编译选项,再次尝试,成功。最后一步就是makemake install了。比较漫长。。。

相关文章

  • CentOS 6 编译安装gcc 5.0+

    CentOS6.5默认安装的gcc版本是4.4.7,而处于某些软件的编译需求,gcc版本要求在5.0以上,因此只能...

  • R 3.6.2 编译安装

    安装 GCC 4.9.2 版本 先编译安装高版本的 GCC(CentOS6) 添加环境变量配置 yum安装 R 的...

  • Docker学习笔记2:Centos7安装Docker

    安装环境 1.Centos 7 环境准备及安装 1.安装相关编译环境 安装编译环境gcc、gcc-c++ 安装完成...

  • Centos7下离线安装PostgreSQL15

    编译环境 及准备 Centos7.5 JDK 1.8 安装编译器 yum -y install gcc gcc-...

  • Centos安装Redis

    Centos安装Redis 选择编译安装 编译和安装所需要的包yum install gcc tcl 下载Redi...

  • CentOS上编译运行PKR

    CentOS上编译运行PKR 安装编译工具相关包 安装gcc-11 编译运行 从 https://github.c...

  • CentOS7升级gcc新版本

    CentOS7编译和安装GCC7.5 CentOS7.5升级gcc到8.3.0版本 Linux系统gcc升级到gc...

  • Centos6.9升级GCC到7.3.0

    Centos6.9的GCC默认是4.8,所以是需要升级GCC的 安装和编译GCC 如果没有xz工具,先安装xz 解...

  • centos7 安装nginx 完整步骤

    centos7 安装nginx 完整步骤 1.安装gcc gcc是用来编译下载下来的nginx源码 yum ins...

  • 在CentOs安装nginx

    如何在CentOs安装nginx 1. 安装编译环境 在正式开始之前,请先将编译环境gcc g++提前安装好,当然...

网友评论

      本文标题:CentOS 6 编译安装gcc 5.0+

      本文链接:https://www.haomeiwen.com/subject/aidpeftx.html