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 zxvf gcc-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->isl。分别进入对应目录中,执行./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、更新libstdc++.so.6的库

    从安装包里查找对应的库:    

    [root@localhost gcc-7.1.0]# find . -name libstdc++.so.6*

    ./prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.23

    ./prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6

    ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.23

    ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6

    ./stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.23

    ./stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6

    将libstdc++.so.6.0.23拷贝到/usr/lib64/目录下

    进行/usr/lib64/目录下,删除libstdc++.so.6(为一个软链接)

    将libstdc++.so.6.0.23软链接为libstdc++.so.6

    即:ln -s libstdc++.so.6.0.23  libstdc++.so.6

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

    [root@localhost codes]# cat hello.cpp

    #include <iostream>

    #include <memory>

    

    void foo(std::shared_ptr<int> i)

    {

            (*i) ++;

    }

    

    int main()

    {

            auto pointer = std::make_shared<int>(10);

            foo(pointer);

    

            std::cout<<*pointer<<std::endl;

    

            return 0;

    }

    

    [root@localhost codes]#

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

    [root@localhost codes]#

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

     11

    [root@localhost codes]#

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

       



 本文转自 XDATAPLUS 51CTO博客,原文链接:http://blog.51cto.com/xdataplus/1935111

相关文章
|
16天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
15 0
|
3月前
|
安全 Linux
CentOS7下快速升级至OpenSSH9.4p1安全版本
CentOS7下快速升级至OpenSSH9.4p1安全版本
149 1
|
3月前
|
安全 Linux Shell
CentOS7下快速升级至OpenSSH9.3p2安全版本
CentOS7下快速升级至OpenSSH9.3p2安全版本
172 0
|
16天前
|
Linux
centos 查看服务器信息 版本cpu
centos 查看服务器信息 版本cpu
12 0
|
2月前
|
存储 Linux 应用服务中间件
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
120 1
|
2月前
|
SQL Linux Shell
centos yum 升级 glibc
在 CentOS 上使用 YUM 升级 GLIBC 库需要谨慎操作,因为 GLIBC 库是系统的基础组件,错误的升级可能导致系统不稳定或与现有应用程序不兼容。 以下是升级 GLIBC 库的步骤: 1. 备份重要数据:在执行任何系统级更改之前,请确保备份重要的数据和配置文件,以防止数据丢失或配置错误。 2. 更新系统:使用 YUM 更新系统软件包,确保系统是最新的稳定版本。可以使用以下命令进行更新: ```sql sudo yum update ``` 3. 备份 GLIBC 库:在升级之前,建议备份当前的 GLIBC 库。可以使用以下命令进行备份: ```bash sudo cp
681 0
|
16天前
|
Linux Apache
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
13 0
|
监控 Linux Apache
CentOS7.0源码安装Apache
CentOS7.0源码安装Apache
1588 0

热门文章

最新文章