c++ - 如何保证共享库在 Linux 发行版之间可移植?

标签 c++ linux qt installation shared-libraries

例如:
QT 曾经为其框架提供离线安装程序
https://www.qt.io/offline-installers
我假设安装程序正在将预构建的运行时库处理到 Linux 机器。 (除其他事项外)
但他们唯一“知道”的是它是 X64 机器。
如果 QT 库是使用 gcc X_Y_Z 在 Linux "X"发行版上预编译的
他们如何确定他们将在具有不同 gcc 版本的任何其他发行版上工作?
问题与 QT 无关,仅作为示例来了解此类安装程序如何工作。
编辑
在 qt 站点中找到了这个,它们确实需要很少的操作系统和编译器版本才能使离线安装程序正常工作
所以也许安装程序的内置软件包很少
发行版和g++版本的组合
它选择在运行时安装哪个?
https://doc.qt.io/qt-5/linux.html

最佳答案

如果您检查 lib 目录,您将看到有多个符号链接(symbolic link)。
因此,对于某个库,它可能如下所示:

libname.so     -> libname.so.1
libname.so.1   -> libname.so.1.8
libname.so.1.8 -> libname.so.1.8.4
libname.so.1.8.4
库供应商通常会为其版本跳转提供一定的 API 兼容性。因此,作为开发人员,您可以链接例如反对libname.so.1你知道库供应商只会在 1.x.y 中添加功能和修复错误吗? .
或者您可以链接到 libname.so.1.8如果您想更具体地了解已安装的版本。
发行版(或供应商)提供的软件包通常会提供那些 API 中存在重大更改的版本。
因此,作为库/应用程序开发人员,您将检查您的依赖项使用的版本方案,并以限制最少的方式进行链接,以保证您的稳定性和兼容性。
对于 c++ 运行时库也是如此:
libstdc++.so        -> libstdc++.so.6.0.28
libstdc++.so.6      -> libstdc++.so.6.0.28
libstdc++.so.6.0.28
编译器版本并不真正相关,相关的是运行时库,它需要与已安装的二进制文件兼容 ABI。
GCC: ABI Policy and Guidelines

“ library API + compiler ABI = library ABI ”
The library ABI is mostly of interest for end-users who have unresolved symbols and are linking dynamically to the C++ Standard library, and who thus must be careful to compile their application with a compiler that is compatible with the available C++ Standard library binary. In this case, compatible is defined with the equation above: given an application compiled with a given compiler ABI and library API, it will work correctly with a Standard C++ Library created with the same constraints.
[…]
Binaries with equivalent DT_SONAMEs are forward-compatibile: in the table below, releases incompatible with the previous one are explicitly noted. If a particular release is not listed, its libstdc++.so binary has the same filename and DT_SONAME as the preceding release.


所以所有libstdc++.so.x如果没有另外提及,版本是向前兼容的。因此,如果您根据 libstdc++.so.6.0.1 构建应用程序,它将与 libstdc++.so.6.0.28 兼容,因此您可以链接到 libstdc++.so.6 .

关于c++ - 如何保证共享库在 Linux 发行版之间可移植?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63343688/

相关文章:

c++ - Boost 过程中缺少异常

c++ - ImageList_LoadImage 找不到位图

c++ - QVariant 到 QDBusArgument

python - 在启动 cron 时从 Python 访问文件系统

linux - 停止 qt 写入/dev/tty0

c++ - 通过 unix 信号优雅地终止 Qt 应用程序

c++ - 结构化绑定(bind)是否适用于 std::vector?

c++ - 具有多个模板参数的模板特化

关闭链接系统中的管道 - Linux C 问题

linux - 在 Linux 中使用 Awk 比较两个文件