CentOS7升级GCC版本(10.1.0)

0.准备—下载升级环境

CentOS7软件库中的GCC是4.8.5版本,在编译C语言时,在用到C99规范时需要自己指定以c99的规范编译-std=c99很麻烦。所以考虑升级一下gcc编译器。GCC必须要我们自己编译源码升级。所以需要做好以下准本工作。

  1. 下载gcc的源码包

https://mirrors.aliyun.com/gnu/gcc/

这个是阿里的镜像,下载起来会快一点。里面最新版本是10.1.0。我下的也是这个版本。

  1. 搭建编译环境
# 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]# ./contrib/download_prerequisites
1.2 配置
  1. 建立编译输出文件。
  2. 配置命令如下
[root@localcomputor gcc-build-10.1.0]# ../temp/gcc-10.1.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

对上述命令进行说明一下:

  • –enable-languages=c,c++:只需要支持c/c++编译器即可。
  • –disable-multilib:指不需要支持多平台的gcc,如果是64位就仅安装64位的gcc。也可以选择支持。选择支持的话,你要先安装32位的开发库,命令如下:
sudo yum install libgcc.i686
sudo yum install glibc-devel.i686

如果不是在所期望安装的目录中还需要加上--prefix=/usr/gcc10.1.0后面改成你自己的目录。

1.3 编译
make -j2

-j的功能如下

-j [jobs], --jobs[=jobs]
            Specifies the number of jobs (commands) to run simultaneously.  If there is more than one -j option, the last one
            is effective.  If the -j option is given without an argument, make will not limit the number of jobs that can run
            simultaneously.

简单来说就是制定同时运行的作业数,相当于多线程。后面的数字自己根据机器的配置定义。不要太高,可能会出现内存溢出的情况。别问我怎么知道的。。。make clean清除之前失败编译的结果。重新编译。编译需要很长时间,运行数越高,时间越短。

1.4 安装
make install

2.测试

gcc -v

gcc版本号
好了到这就结束了。。。。


参考链接:
centOS上gcc安装
centos7升级gcc8.2

你可能感兴趣的:(C语言学习,Linux,linux,centos,c++,gcc/gdb编译调试,c语言)