Centos6升级gcc到7.1.0版本

深度链接 / 2023-12-06 21:47:55 / 94

ImportError: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found

一、系统环境

[root@wrx ~]# uname -sir
Linux 2.6.32-642.13.1.el6.i686 i386
[root@wrx ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

[root@wrx ~]# rpm -qa | grep gcc
libgcc-4.4.7-23.el6.i686
gcc-4.4.7-23.el6.i686
gcc-c++-4.4.7-23.el6.i686

二、错误

[root@wrx proc]# python3
Python 3.4.4 (default, Jun 18 2017, 19:00:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyV8  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/PyV8.py", line 32, in <module>
    import _PyV8
ImportError: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/local/lib/python3.4/site-packages/_PyV8.so)

三、查看系统中GLIBCXX所有版本

[root@wrx ~]# strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

四、升级GCC

使用源码编译安装
1、获取安装包
在http://ftp.gnu.org/gnu/gcc/上选择下载自己所需安装的版本
我选安装的gcc-7.1.0版本
wget http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz

2、解压
[root@wrx tmp]# tar -zxvf gcc-7.1.0.tar.gz 

3、下载安装需要依赖项
[root@wrx tmp]# cd gcc-7.1.0
[root@wrx gcc-7.1.0]# ./contrib/download_prerequisites 

4、建立一个文件夹存放编译出文件
[root@wrx gcc-7.1.0]# mkdir gcc-build-7.1.0
[root@wrx gcc-7.1.0]# cd gcc-build-7.1.0/

5、生成MakeFile文件
[root@wrx gcc-build-7.1.0]# ../configure -enable-checking=release -enable-languages=c,c++

6、编译
[root@wrx gcc-build-7.1.0]# make -j4
此步骤会非常耗时,耐心等待

7、安装
[root@wrx gcc-build-7.1.0]# make install

8、备份
[root@wrx lib]# cd /usr/lib
[root@wrx lib]# pwd
/usr/lib
[root@wrx lib]# mv libstdc++.so.6 libstdc++.so.6.bk

[root@wrx lib]# pwd
/usr/local/lib
[root@wrx lib]# cp libstdc++.so.6.0.23 /usr/lib/

9、建立软连接
[root@wrx lib]# ln -s libstdc++.so.6.0.23 libstdc++.so.6
[root@wrx lib]# strings libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH