老GCC不能自动找到新版本libstdc++? [英] Old GCC can not automatically find the new version libstdc++?

查看:100
本文介绍了老GCC不能自动找到新版本libstdc++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用名为 DocToText 的第 3 方库和 gcc 4.4.7.

I'm trying to use the 3rd-party lib, called DocToText, with gcc 4.4.7.

我编译了程序:

g++ -I./doctotext/-L./doctotext/-Wl,-rpath=./doctotext -ldoctotext -o 示例 test_doctotext.cpp

一开始返回libstdc++.so.6: version GLIBCXX_3.4.15 not found

我手动下载了新版本,重新链接,结果如下

I manually downloaded the newer version, and re-linked, here is the result

[root@mail]~xian# find / -name "libstdc++.so.6"
/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6
[root@mail]~xian# strings /lib64/libstdc++.so.6 | grep GLIBCXX_3.4.15
GLIBCXX_3.4.15
[root@mail]~xian# strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX_3.4.15
GLIBCXX_3.4.15

但是当我再次编译时,它返回:

But when I compiled again, it returned:

[root@mail]~xian# g++ -I./doctotext/ -L./doctotext/ -Wl,-rpath=./doctotext -ldoctotext -o example test_doctotext.cpp 
./doctotext//libdoctotext.so: undefined reference to `std::__detail::_List_node_base::swap(std::__detail::_List_node_base&, std::__detail::_List_node_base&)@GLIBCXX_3.4.15'
./doctotext//libdoctotext.so: undefined reference to `std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)@GLIBCXX_3.4.15'
./doctotext//libdoctotext.so: undefined reference to `std::__detail::_List_node_base::_M_unhook()@GLIBCXX_3.4.15'
./doctotext//libdoctotext.so: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)@GLIBCXX_3.4.15'
collect2: ld returned 1 exit status

我也试过

g++ -I./doctotext/ -L./doctotext/ -L/lib64/ -Wl,-rpath=./doctotext,-rpath=/lib64 -ldoctotext -lstdc++ -o example test_doctotext.cpp

,我得到了同样的错误(未定义的引用).

, and I got the same errors (undefined reference).

libdoctotext.so 确实链接到/lib64/libstdc++.so.6

libdoctotext.so indeed link to /lib64/libstdc++.so.6

[root@mail]~xian# ldd doctotext/libdoctotext.so | grep libstdc++.so.6
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f96c7ab4000)

幸运的是,我找到了两种方法来解决这个问题:

Fortunately, I found two method to solve this problem:

  1. 使用较新的 gcc:我使用了 gcc 9.1.1 (with scl),然后 g++ -I./doctotext/-L./doctotext/-Wl,-rpath=./doctotext -ldoctotext -o example test_doctotext.cpp工作.
  2. 用 gcc 4.4.7 指定 libstdc++.so.6 的路径:g++ -I./doctotext/-L./doctotext/-Wl,-rpath=./doctotext -ldoctotext/lib64/libstdc++.so.6 -o 示例 test_doctotext.cpp

但是我真的很好奇为什么我的gcc 4.4.7不能链接到系统默认路径下的那个libstdc++?

But I'm really curious about why my gcc 4.4.7 can not link to that libstdc++ under the system default path?

libstdc++ 的版本是否以某种方式与 gcc 的版本紧密耦合?

Is the version of libstdc++ be tightly coupled to the version of gcc in someway?

==================================================================================

===============================================================================

最终,我发现 gcc 会使用

Eventually, I found gcc would use

[root@mail]/usr/lib64# find / -name "libstdc++.so"
/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/libstdc++.so
/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libstdc++.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.so
[root@mail]/usr/lib64# ll /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.so
lrwxrwxrwx. 1 root root 37 Aug 21 15:22 /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.so -> ../../../../lib64/libstdc++.so.6.0.13

6.0.13 没有 GLIBCXX_3.4.15

6.0.13 doesn't have GLIBCXX_3.4.15

我重新链接到 libstdc++.so.6.0.17,问题解决

I re-link this to libstdc++.so.6.0.17, problem solved

推荐答案

每个 GCC 版本都伴随着自己的 libstdc++ 版本.

Every GCC release is accompanied by its very own libstdc++ release.

C++ 标准库(以及 libsupc++ 等支持库)通常依赖于编译器中的特定实现细节,包括错误以及由于缺陷报告等导致的特定行为变化.有时,即使是新的 GCC 版本也需要匹配的 binutils(链接器)版本,因为代码的生成方式已更改为使用仅在较新的链接器中可用的特定功能.

The C++ standard library (and support libraries like libsupc++) often rely on specific implementation details in the compiler, including bugs, and specific changes in behaviour due to defect reports etc. Sometimes even a new GCC release also needs a matching binutils (linker) release, as the way the code is generated changed to use a specific feature only available in the newer linker.

您可以通过将该路径传递给编译器/链接器来将其显式链接到系统 libstdc++,但我不建议这样做,因为 ABI 可能以不兼容的方式更改.

You can explicitly link it to the system libstdc++ by passing that path to the compiler/linker, but I don't recommend it, as the ABI may have changed in an incompatible way.

这篇关于老GCC不能自动找到新版本libstdc++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆