centos 编译安装gcc8.1

gcc升级到8.1了,试试编译一下。

截止 2018-05-03 最新版本:https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.gz

更多版本查找:http://ftp.gnu.org/gnu/gcc/

另外可参考清华镜像,虽然不太全,但速度快:https://mirrors.tuna.tsinghua.edu.cn/gnu

安装基本编译环境

yum install -y glibc-devel bison flex texinfo build-essential

#gcc gcc-c++ make

下载依赖库

./contrib/download_prerequisites

默认使用ftp协议,有可能下载失败,可以考虑http下载。https://gcc.gnu.org/pub/gcc/infrastructure/

根据提示下载依赖,注意提示失败的版本号:

wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpc/mpc-1.0.3.tar.gz
tar xvfz mpc-1.0.3.tar.gz
ln -s mpc-1.0.3 mpc

wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/gmp-6.1.0.tar.bz2

tar xvfj gmp-6.1.0.tar.bz2
ln -s gmp-6.1.0 gmp

wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpfr/mpfr-3.1.4.tar.bz2

tar xvfj mpfr-3.1.4.tar.bz2
ln -s mpfr-3.1.4 mpfr

# 还有一个 isl-0.18.tar.bz2 清华镜像中没有
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2

tar xvfj isl-0.18.tar.bz2
ln -s isl-0.18 isl

创建编译目录

mkdir gcc-build; cd $_

生成Makefile文件

../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

编译(注意:此步骤非常耗时,我在虚机里用了203分钟)

make -j4

-j4选项是make对多核处理器的优化,如果失败尝试去掉该参数。

安装

make install

完成后记得退出登录重新刷新一下profile,或者手动刷新:

source /etc/profile

检查一下:

[root@localhost gcc-build]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 8.1.0 (GCC)

猜你喜欢

转载自my.oschina.net/polly/blog/1806743
今日推荐