升级 GCC 支持C++11 或 configure: error: *** A compiler with support for C++11 language features is required.

configure: error: *** A compiler with support for C++11 language features is required.


 参考链接:

(1)升级 GCC 支持C++11

 

(2)解决/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found的问题方法总结


 

一、错误发生情景:

使用sh setup.sh安装软件时,报以下错误:

...
configure: error: *** A compiler with support for C++11 language features is required.
---
ERROR: failed to configure xapian-core-scws, see 'setup.log' for more detail

二、错误原因:

  gcc版本太低了


 

三、解决问题:

  (1)查看当前的gcc版本:

    gcc -v

    结果:gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)

  (2)下载高版本的gcc:

    wget ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz

  (3)解压:

    tar -zxvf gcc-8.3.0.tar.gz

  (4)进入目录

    cd gcc-8.3.0

  (5)配置

    ./configure --prefix=/usr/local/gcc-8.3.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib

      注意,如果出现错误以下错误:  

...
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
...

      请看文章底部的错误解决方法。

  (6)编译

      make

  (7)安装

      make install

  (8)查看版本

      gcc -v

      如果发现版本没有变化,

      可以删除旧版本的gcc,如果旧版的是用yum安装的,可以使用yum remove gcc。

      然后把新安装的gcc的bin目录添加到环境变量中,/etc/pfofile文件中。

      再查看版本,是否已变成最新安装的版本。

  (9)更新标准库

      (这一步,应该是需要的,gcc升级后,标准库还是旧的,可能影响一些编译操作。)

      1、进入到刚才安装新的GCC的目录中:cd /usr/local/gcc-8.3.0

      2、进入到库目录:cd lib64 (注意:系统如果是64位的就进入到lib64目录,否则进入到lib目录)

      3、查看当前库的最搭版本:ls,结果看到:libstdc++.so.6.0.25

      4、复制到系统默认的库目录下:

        cp libstdc++.so.6.0.25 /usr/lib64/  (注意:系统如果是32:cp libstdc++.so.6.0.25 /usr/lib/)
      
5、进入到/usr/lib64下,查看相关的版本信息
        
ls -l | grep libstdc++

        结果:
        
...   libstdc++.so.6 -> libstdc++.so.6.0.13
        ...  libstdc++.so.6.0.13
                            ...   libstdc++.so.6.0.25
      6、删除旧的软连接:
        rm -f libstdc++.so.6
      7、建立新的软连接:
        ln -s libstdc++.so.6.0.25 libstdc++.so.6

      8、查看标准库最新的版本:

        strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX        

GLIBCXX_3.4
GLIBCXX_3.4.1
.
.
.
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

        可以看到,已更新到最新的25版本。


 

可能遇见的错误:

  在执行.configure命令时,可能遇到以下错误:

...省略
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
http://gcc.gnu.org/install/prerequisites.html for additional info. If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files. They may be located in separate packages.

错误说明,安装gcc需要这三个依赖:GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+。

错误中还指出了下载页面的地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/。

  1、打开链接:ftp://gcc.gnu.org/pub/gcc/infrastructure/。

  2、找到需要的三个包地址,下载下来:

      wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2

      wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2

      wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz

  3、安装GMP:      

tar -jxvf gmp-6.1.0.tar.bz2
cd gmp-6.1.0
./configure
make && make install

  4、安装MPFR:

tar -jxvf mpfr-3.1.4.tar.bz2
cd mpfr-3.1.4
./configure
make && make install

  5、安装MPC: 

tar -zxvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure
make && make install

 

 


  

    

posted @ 2019-03-15 15:28  学知无涯  阅读(18874)  评论(0编辑  收藏  举报