C++11 gcc升级到5.2.0后报错:/usr/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.17' not found

来源:互联网 发布:快易宝软件下载 编辑:程序博客网 时间:2024/05/21 08:02

我的linux操作系统为centos6.5,为了能编译C++11程序,需要对gcc编译器进行升级(centos6.5默认安装的gcc编译器是4.4.7,支持C++11需要至少4.8.1)到gcc5.2.0,参照《【Linux】CentOS6.5 gcc升级方式》对编译器进行了升级,耗时两个多小时。
等编译升级就绪,编译了C++11的代码,运行时,报错:

/usr/lib64/libstdc++.so.6: version ‘GLIBCXX_3.4.17’ not found

查看/usr/lib64/libstdc++.so.6,发现指向libstdc++.so.6.0.13,只支持到3.4.13

[root@t2-centos6 lib64]# cd /usr/lib64
[root@t2-centos6 lib64]# ll libstdc++.so.6*
lrwxrwxrwx. 1 root root 19 12月 21 11:14 libstdc++.so.6 -> libstdc++.so.6.0.13
-rwxr-xr-x. 1 root root 987096 12月 21 11:18 libstdc++.so.6.0.13
[root@t2-centos6 lib64]# 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_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

再去之前编译的gcc5.2.0目录查看

[root@t2-centos6 lib64]# ll /usr/local/build/gcc-5.2.0/x86_64-unknown-linux-gnu//libstdc++-v3/src/.libs/
总用量 70532
-rw-r–r–. 1 root root 45072 12月 20 13:49 compatibility-atomic-c++0x.o
-rw-r–r–. 1 root root 141944 12月 20 13:49 compatibility-c++0x.o
-rw-r–r–. 1 root root 20208 12月 20 13:49 compatibility-chrono.o
-rw-r–r–. 1 root root 35576 12月 20 13:49 compatibility-condvar.o
-rw-r–r–. 1 root root 8488 12月 20 13:49 compatibility-debug_list-2.o
-rw-r–r–. 1 root root 10464 12月 20 13:49 compatibility-debug_list.o
-rw-r–r–. 1 root root 187104 12月 20 13:49 compatibility.o
-rw-r–r–. 1 root root 115856 12月 20 13:49 compatibility-thread-c++0x.o
-rw-r–r–. 1 root root 30126742 12月 20 13:49 libstdc++.a
-rw-r–r–. 1 root root 29925050 12月 20 13:49 libstdc++convenience.a
lrwxrwxrwx. 1 root root 26 12月 20 13:49 libstdc++convenience.la -> ../libstdc++convenience.la
lrwxrwxrwx. 1 root root 15 12月 20 13:49 libstdc++.la -> ../libstdc++.la
-rw-r–r–. 1 root root 965 12月 20 13:49 libstdc++.lai
lrwxrwxrwx. 1 root root 19 12月 20 13:49 libstdc++.so -> libstdc++.so.6.0.21
lrwxrwxrwx. 1 root root 19 12月 20 13:49 libstdc++.so.6 -> libstdc++.so.6.0.21
-rwxr-xr-x. 1 root root 11582206 12月 20 13:49 libstdc++.so.6.0.21 //gcc 5.2.0编译出的so文件

上面的文件列表中可以看出gcc5.2.0已经编译出libstdc++.so.6.0.21,但在安装时(make install)并没有更新/usr/lib64/libstdc++.so.6的软链接,所以libstdc++.so仍然指向gcc4.4.7的旧so文件。
所以解决办法,就是将libstdc++.so.6.0.21复制到/usr/lib64,然后修改libstdc++.so.6软链接

[root@t2-centos6 lib64]#cd /usr/local/build/gcc-5.2.0/x86_64-unknown-linux-gnu//libstdc++-v3/src/.libs/
[root@t2-centos6 lib64]# cp libstdc++.so.6.0.21 /usr/lib64 //复制到/usr/lib64
[root@t2-centos6 lib64]# ln -sf libstdc++.so.6.0.21 libstdc++.so.6 // 修改libstdc++.so.6软链接指向新的so

再次查看libstdc++.so.6的版本支持情况,已经支持到GLIBCXX_3.4.21了,满足要求

[root@t2-centos6 lib64]# 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_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

再次运行程序就正常了

0 0
原创粉丝点击