Centos7升级g++
https://www.cnblogs.com/ToBeExpert/p/10297697.html
先下载:
git clone https://github.com/gcc-mirror/gcc
或者ftp下载:http://mirrors.nju.edu.cn/gnu/gcc/
首先:
yum -y install texinfo
如果不执行这个命令的话,那么在执行第四步的配置的时候,会出现makeinfo:could not find this command。
安装依赖库
据说原来升级gcc的时候超级麻烦因为它依赖了mpfr、gmp、mpc 和isl共四个库,它们下载起来也很麻烦,现在事情变得简单了很多, 在gcc目录下执行一次执行以下命令:
./contrib/download_prerequisites #作用是自动下载gcc的4个依赖包
mkdir build
cd build
../configure --prefix=/usr --enable-multilib --enable-languages=c,c++ -disable-multilib
这条命令的作用实际上就是生成合适的Makefile,执行的过程中出现了一个警告:
configure: WARNING: using in-tree isl, disabling version check
*** This configuration is not supported in the following subdirectories:
gnattools gotools target-libada target-libhsail-rt target-libgfortran target-libbacktrace target-libgo target-libffi target-libobjc target-liboffloadmic
(Any other directories should still work fine.)
说明一下,这个警告,我看了很多人的博客,都没有提到过,有的博客倒是把它列出来了,但是却没有给出解决的办法。
配置成功以后,执行命令:
yum groupinstall "Development Tools"
编译
make
安装
make install
g++ -v 看看是否更新了版本
安装完成以后,如果gcc编译程序的时候出现错误:
//usr/lib64/libstdc++.so.6: undefined reference to `libiconv'
//usr/lib64/libstdc++.so.6: undefined reference to `libiconv_close'
//usr/lib64/libstdc++.so.6: undefined reference to `libiconv_open'
collect2: error: ld returned 1 exit status
需要安装:
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
./configure --prefix=/usr
make
make install
运行
ldconfig
ldconfig: /usr/lib64/libstdc++.so.6.0.28-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
只要删除/usr/lib64/libstdc++.so.6.0.28-gdb.py这个文件重新运行ldconfig即可