c++ - 链接到旧版本 g++ 编译的动态库时,我应该注意什么潜在问题吗?

标签 c++ linux ubuntu linker g++

有别人提供的动态库,我管不了。我所知道的是,大多数上述库都是编译的 g++4.9.4 & g++4.8.4 支持C++11,很少有库 由 g++11.1.0 编译,支持 C++14。而且我必须使用支持 C++17 的较新的 g++ 来编译我的项目。我打算在 Ubuntu20.4 上使用 g++11.3.0

链接老版本g++编译的动态库有什么潜在问题需要注意吗?

最佳答案

TL;DR:您描述的动态库链接应该“正常工作”,前提是您使用较新版本的 g++ 链接可执行文件。

你提到的 GNU g++ 的两个版本都使用 libstdc++ (特别是 libstdc++.so.6.0.*)来实现 C++11/C++17 所需的支持库。

在大多数情况下,较新版本的 libstdc++ 保持其 ABI policy manual 的内容调用“向前兼容性”:

Versioning gives subsequent releases of library binaries the ability to add new symbols and add functionality, all the while retaining compatibility with the previous releases in the series. Thus, program binaries linked with the initial release of a library binary will still run correctly if the library binary is replaced by carefully-managed subsequent library binaries. This is called forward compatibility.

对于异常情况(可能与您的情况无关),有一些注意事项:

  1. 这假设所有对象都是使用兼容的 CPU ABI/架构标志构建的(即 -march-mcpu-m64 等. 如果有的话),这是将库正确链接在一起的一般要求(无论编译器版本如何)。这些选项的编译器默认值应该为您的系统选择兼容的设置,因此这种挑战通常只出现在您故意更改为非默认 ABI 的交叉编译场景中。
  2. 一些 C++ 库类(例如 std::stringstd::list)的内部表示随着时间的推移发生了变化,如果两个库可能会导致问题正在共享对相同 C++ 对象的访问。只有在 g++ 版本不同的库接口(interface)中传递 C++ 库对象或对它们的引用时,这才会成为问题。

关于c++ - 链接到旧版本 g++ 编译的动态库时,我应该注意什么潜在问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74315750/

相关文章:

ubuntu - 带有 TLS 的 Mosquitto MQTT 代理 - 客户端连接错误

c++ - 事件 wxWidgets

c++ - MFC CToolBar 帮助/链接?

android - 通过 Wifi-Direct 连接 Linux 和 Android(BeagleBone Black 和 Android-app)

linux - 在 Linux 服务器上将 Excel 提取为文本

ubuntu - "echo ' PATH ="$HOME/.local/bin/:$PATH"' >>~/.bashrc "有什么作用?

c++ - Qt 自定义委托(delegate)崩溃,没有错误代码

c++ - 一个好的 vector 散列函数

linux - 为什么 autoconf 会错误地找到一个以后不可用的功能?

apache - Confluence 中的 JIRA 问题/过滤器宏生成无效链接