CentOS 7 源码编译安装高版本gcc


在编译MySQL 8.0 时,提示GCC版本过低(4.8.5),需要升级GCC到5.3及以上版本,按照网上教程,源码编译GCC 9.2.0版本,虽然遇到一点问题,不过总算顺利通过,记录一下GCC源码编译过程。

环境:

  • 操作系统:CentOS 7.2
  • GCC版本:9.2.0
一、下载GCC源码

下载gcc源码:http://mirror.hust.edu.cn/gnu/gcc/

这里以安装gcc 9.2.0版本为例。

1. 下载gcc源码:
wget http://mirror.hust.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz

2. 解压:
tar xf gcc-9.2.0.tar.gz

3. 下载依赖包
cd gcc-9.2.0
./contrib/download_prerequisites

如果上述这一步卡住,无反应,可以考虑手动下载依赖包到GCC源码根目录。如下:
wget http://ftp.gnu.org/pub/gnu/gmp/gmp-6.1.0.tar.bz2
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.bz2
wget http://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2

再次执行:
./contrib/download_prerequisites --no-verify

解压gmp-6.1.0.tar.bz2这个文件时,会报错,如下:

bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Inappropriate ioctl for device
        Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

tar: Child returned status 2
tar: Error is not recoverable: exiting now


安装 bzip2 解压。

yum install bzip2

如果还不行,可以考虑直接把 .bz2 的压缩包在 windows 上解压的目录拷贝到 CentOS GCC 源码根目录下解决。

再次执行:
./contrib/download_prerequisites --no-verify

运行成功,如下:
All prerequisites downloaded successfully.

二、编译源码

配置编译选项:
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

编译:
make

报错:
makeinfo: command not found

安装texinfo:
yum install perl-Text-Unidecode
yum install perl-libintl
yum install texinfo

然后再次执行:
make

这个过程会持续很长时间,大约2~3个小时。(1核1G的虚拟机)

安装:
make install

验证gcc版本:
cd /usr/local/bin/
./gcc --version

gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying 
conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.

gcc 9.2.0 版本编译成功完成。


文章评论

0条评论