微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos 源码升级g++版本

1、用GNU上下载对应版本的源码包到本地,官网:http://ftp.gnu.org/gnu/gcc/

这里选用最新的包:

wget http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz

2、解压对应的包,然后进入到gcc-7.1.0目录下:

tar zxvfgcc-7.1.0.tar.gz

3、下载更新所需要的依赖包,执行:

./contrib/download_prerequisites

下载完成后,会看到新生成文件

-rw-r--r-- 1 root root 2383840 Jun 12 12:34 gmp-6.1.0.tar.bz2

-rw-r--r-- 1 root root 1279284 Jun 12 12:34 mpfr-3.1.4.tar.bz2

-rw-r--r-- 1 root root 669925 Jun 12 12:34 mpc-1.0.3.tar.gz

-rw-r--r-- 1 root root 1626446 Jun 12 12:34 isl-0.16.1.tar.bz2

lrwxrwxrwx 1 root root 12 Jun 12 12:34 gmp -> ./gmp-6.1.0/

lrwxrwxrwx 1 root root 13 Jun 12 12:34 mpfr -> ./mpfr-3.1.4/

lrwxrwxrwx 1 root root 12 Jun 12 12:34 mpc -> ./mpc-1.0.3/

lrwxrwxrwx 1 root root 13 Jun 12 12:34 isl -> ./isl-0.16.1/

接下来安装对应的依赖包,依赖包可能存在一定依赖,请按照顺序进行安装,gmp->mpfr->mpc->ils。分别进入对应目录中,执行./configure ---> make ---> make install 即可。(这个顺序,亲测可行)

4、生成g++的makefile文件

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

5、编译

make

使用make -j4,采用多核优化提高速度

6、安装

make install


7、到此安装完毕,看到一下gcc,g++的版本

[root@localhost gcc-7.1.0]# gcc --version

gcc (GCC) 7.1.0

copyright (C) 2017 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.


[root@localhost gcc-7.1.0]# g++ --version

g++ (GCC) 7.1.0

copyright (C) 2017 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.

8、写个简单的Hello world测试一下

[root@localhost codes]# cat hello.cpp

#include <iostream>


int main()

{

std::cout<<"hello,world"<<std::endl;


return 0;

}


[root@localhost codes]#

[root@localhost codes]# g++ hello.cpp -std=c++14

[root@localhost codes]#

[root@localhost codes]# ./a.out

hello,world

[root@localhost codes]#

9、看来没问题,升级结束

j_0051.gif

原文地址:https://www.jb51.cc/centos/377201.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。