0.准备—下载升级环境
CentOS7软件库中的GCC是4.8.5版本,在编译C语言时,在用到C99规范时需要自己指定以c99的规范编译-std=c99
很麻烦。所以考虑升级一下gcc编译器。GCC必须要我们自己编译源码升级。所以需要做好以下准本工作。
- 下载gcc的源码包
https://mirrors.aliyun.com/gnu/gcc/
这个是阿里的镜像,下载起来会快一点。里面最新版本是10.1.0。我下的也是这个版本。
- 搭建编译环境
# yum -y install gcc
# yum -y install gcc-c++
# yum -y install bzip2
说明一下:如果没有安装bzip2,会在下载依赖库时报如下错误
tar (child): lbzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
1.安装
1.1 安装依赖库
gcc依赖了mpfr、gmp、mpc 和is这四个库,现在在gcc的文件中整合了一个shell脚本,我们通过执行脚本文件快速安装依赖。注意:该脚本需要在gcc文件夹内执行。
[root@localcomputor gcc-10.1.0]# ./cont