难道不是 C++标准库向后兼容?

发布于 2024-08-25 04:53:32 字数 1855 浏览 7 评论 0原文

我正在 64 位 Linux 系统上工作,尝试构建一些依赖于我拥有二进制文件的第三方库的代码。在链接期间,我收到其中一个库的一系列未定义引用错误,表明链接器无法解析对标准 C++ 函数/类的引用,例如:

librxio.a(EphReader.o): In function `gpstk::EphReader::read_fic_data(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
EphReader.cpp:(.text+0x27c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
EphReader.cpp:(.text+0x4e8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'

我并不是真正的 C++ 程序员,但这对我来说看起来像它找不到标准库。做了更多研究,当我查看 librxio 对标准库的依赖项时,我得到了以下信息:

$ ldd librxio.so.16.0
./librxio.so.16.0: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./librxio.so.16.0)
   libm.so.6 => /lib64/libm.so.6 (0x00002aaaaad45000)
   libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaaafc8000)
   libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaab2c8000)
   libc.so.6 => /lib64/libc.so.6 (0x00002aaaab4d7000)
   /lib64/ld-linux-x86-64.so.2 (0x0000555555554000)

所以我读到说 librxio (第三方库之一)至少需要 v3.4.9 的标准库。但我安装的版本是4.1.2:

$ rpm -qa | grep libstdc
compat-libstdc++-33-3.2.3-61.x86_64
libstdc++-devel-4.1.2-14.el5.i386
libstdc++-devel-4.1.2-14.el5.x86_64
libstdc++-4.1.2-14.el5.x86_64
libstdc++-4.1.2-14.el5.i386

这不应该起作用吗?共享对象主编号为 6,与 v3.4.9 相同。在这个层面上,这不是应该向后兼容吗?看起来第三方库正在寻找比我安装的版本更早的标准库;但是共享库的主版本号相同的版本之间不存在向后兼容性吗?再说一次,我并不是一个真正的 C++ 程序员;我只是一个 C++ 程序员。但我不明白问题是什么。

任何建议都非常感激。谢谢。

I'm working on a 64-bit Linux system, trying to build some code that depends on third-party libraries for which I have binaries. During linking, I get a stream of undefined reference errors for one of the libraries, indicating that the linker couldn't resolve references to standard C++ functions/classes, e.g.:

librxio.a(EphReader.o): In function `gpstk::EphReader::read_fic_data(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
EphReader.cpp:(.text+0x27c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
EphReader.cpp:(.text+0x4e8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'

I'm not really a C++ programmer, but this looks to me like it can't find the standard library. Doing some more research, I got the following when I looked at librxio's dependency for the standard library:

$ ldd librxio.so.16.0
./librxio.so.16.0: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./librxio.so.16.0)
   libm.so.6 => /lib64/libm.so.6 (0x00002aaaaad45000)
   libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaaafc8000)
   libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaab2c8000)
   libc.so.6 => /lib64/libc.so.6 (0x00002aaaab4d7000)
   /lib64/ld-linux-x86-64.so.2 (0x0000555555554000)

So I read that as saying that librxio (one of the third-party libraries) requires at least v3.4.9 of the standard library. But the version I have installed is 4.1.2:

$ rpm -qa | grep libstdc
compat-libstdc++-33-3.2.3-61.x86_64
libstdc++-devel-4.1.2-14.el5.i386
libstdc++-devel-4.1.2-14.el5.x86_64
libstdc++-4.1.2-14.el5.x86_64
libstdc++-4.1.2-14.el5.i386

Shouldn't this work? The shared object major number is 6, same as for v3.4.9. At this level, shouldn't this be backward compatible? It seems like the third-party library is looking for an earlier version of the standard library than what I have installed; but isn't there backward compatibility between versions with the same major number for the shared library? Again, I'm not really a C++ programmer; but I don't see what the problem is.

Any advice greatly appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离去的眼神 2024-09-01 04:53:32

C++ 运行时往往是特定于编译器的,并且您正在寻找的库肯定是特定于编译器版本的。请记住,即使界面没有改变,内部结构也可能会改变。

您要么需要获取使用相同的编译器构建的库,要么需要获取使用相同的编译器构建的库。您拥有的库版本,或安装适当的编译器/库版本。

C++ runtimes tend to be compiler specific and the library that you're looking for definitely is compiler version specific. Keep in mind that even if the interface doesn't change, the internals might.

You'll either need to acquire libraries built with the same compiler & library versions that you have, or install the appropriate compiler/library versions.

笑梦风尘 2024-09-01 04:53:32

您从哪里获得librxio.so.16.0?我认为它是用GCC编译的> 4.1,因此它可能不适用于 4.1 运行时。

Where did you get librxio.so.16.0? I think it's compiled with GCC > 4.1, and so it may not work with 4.1 runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文