如何在 Linux 中对共享库进行版本控制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7553184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:21:08  来源:igfitidea点击:

How to do versioning of a shared library in Linux?

c++clinuxshared-libraries

提问by CrazyC

Windows provides the resource file for version information for an application and DLL. The resource file includes information like version, copyright and manufacturer.

Windows 为应用程序和 DLL 的版本信息提供资源文件。资源文件包括版本、版权和制造商等信息。

We have an shared library and like to add version information. How can we do it on Linux with a shared library?

我们有一个共享库,喜欢添加版本信息。我们如何使用共享库在 Linux 上做到这一点?

采纳答案by nos

The short version is that you do this via the sonameof the library. Read chapter 3 at http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.htmlas well as chapter 3.3 ABI Versioning at http://www.akkadia.org/drepper/dsohowto.pdf

简短的版本是您通过库的 soname来执行此操作。阅读http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html 上的第 3 章以及http://www.akkadia.org/drepper/dsohowto.pdf 上的第 3.3 ABI 版本控制

回答by qdot

Linux uses the following strategy - you (the system maintainer) provide symlinks from a 'specific' shared library file, like this:

Linux 使用以下策略 - 您(系统维护者)提供来自“特定”共享库文件的符号链接,如下所示:

lrwxrwxrwx 1 root root    16 2011-09-22 14:36 libieee1284.so -> libieee1284.so.3
lrwxrwxrwx 1 root root    20 2011-09-22 14:36 libieee1284.so.3 -> libieee1284.so.3.2.2
-rw-r--r-- 1 root root 46576 2011-07-27 13:08 libieee1284.so.3.2.2

This way, developers can link either against -lieee1284 (any version ABI), or libieee1284.so.3 or even to the specific release and patch version (3.2.2)

这样,开发人员可以链接到 -lieee1284(任何版本的 ABI)或 libieee1284.so.3 甚至特定的发行版和补丁版本 (3.2.2)

回答by thiton

The best way to handle this is using libtool, which does the versioning for you.

处理此问题的最佳方法是使用 libtool,它会为您进行版本控制。

Essentially, version information is not (or not primarily, don't know from my head) encoded in the library itself, but rather in its filename. Version numbers are normally given in three-dot format, with the major number increasing for each break in downward ABI compatibility, the middle for breaks in upward ABI compatibility, and the minor for patches that did not change the ABI.

本质上,版本信息不是(或者不是主要的,我不知道)在库本身中编码,而是在它的文件名中。版本号通常以三点格式给出,主要编号随着向下 ABI 兼容性的每个中断而增加,中间表示向上 ABI 兼容性中断,次要编号表示未更改 ABI 的补丁。

Like qdot noted, symlinks in the lib directory provide the essential versioning. There is a symlink without a version number (libfoo.so) for the currently installed development headers, a symlink with a major number for each installed major version (libfoo.so.1) and a real file with the full version number. Normally, programs are linked to use libfoo.so.1 at runtime so that multiple major versions may coexist.

就像 qdot 指出的那样,lib 目录中的符号链接提供了必要的版本控制。当前安装的开发头文件有一个没有版本号的符号链接 (libfoo.so),每个安装的主要版本都有一个主要编号的符号链接 (libfoo.so.1) 和一个具有完整版本号的真实文件。通常,程序在运行时链接到使用 libfoo.so.1,以便多个主要版本可以共存。