针对符号链接而不是 soname 进行链接

发布于 2024-10-09 20:56:25 字数 595 浏览 7 评论 0原文

我有一个 Linux 应用程序,它在链接器行上链接到: libpython2.6.so

这最终解析为 libpython.2.6.so.1.0

/usr/lib/libpython2.6.so -> libpython2.6.so.1
/usr/lib/libpython2.6.so.1 -> libpython2.6.so.1.0

,其中嵌入了 SONAME ,因此我只能将其链接到完整版本的名称。

 g++ foo.cc /usr/lib/libpython2.6.so
 ldd ./a.out | grep python
        libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00007fd36f7ab000)

这意味着如果存在 libpython2.6.so.1.1,我的应用程序最终将崩溃。是否有办法强制我的应用程序使用通用名称 libpython2.6,而不是 libpython2.6.so.1.0?

我使用了这么小的一组 python API,我认为我应该可以安全地链接到该库的更通用的版本名称。

I have an linux application, which on the linker line links against:
libpython2.6.so

This ultimately resolves to libpython.2.6.so.1.0

/usr/lib/libpython2.6.so -> libpython2.6.so.1
/usr/lib/libpython2.6.so.1 -> libpython2.6.so.1.0

Which has SONAME embedded in it so that I am stuck with it linking against the fully versioned name.

 g++ foo.cc /usr/lib/libpython2.6.so
 ldd ./a.out | grep python
        libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0x00007fd36f7ab000)

This means that my application will ultimately break if there is ever a libpython2.6.so.1.1. Is there anyway to force my application to use the generic name libpython2.6, instead of libpython2.6.so.1.0?

I use such a small set of the python API, that I think I should be safe linking against a more generic version name of the library.

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

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

发布评论

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

评论(2

花伊自在美 2024-10-16 20:56:25

看看``3.1.1。 http://tldp.org/HOWTO/Program 中的共享库名称 '' -Library-HOWTO/shared-libraries.html ,这可以帮助您了解共享库的命名方法。

每个共享库都有一个特殊的
名称称为soname''。索名
具有前缀
lib'',其名称
库,短语.so'',
后跟句点和版本
每当
界面发生变化(作为一个特殊的
例外,最低级别的C
库不以
lib''开头)。一个
完全限定的 soname 包含为
为其所在目录添加前缀;在一个
工作体系齐全
soname 只是一个符号链接
共享库的“真实姓名”。

每个共享库也有一个“真实的
name'',这是文件名
包含实际的库代码。
真实姓名添加到 soname a
时期,少数,另一个
期限和发行号。这
最后一个周期和版本号是
选修的。次要版本号和版本
号码支持配置控制
让你确切地知道什么
库的版本是
安装。请注意这些数字
可能与数字不同
用于描述库
文档,尽管这确实使
事情变得更容易。

此外,还有一个名字
编译器在请求时使用
库,(我将其称为“链接器
name''),这只是 soname
没有任何版本号。

Have a look at ``3.1.1. Shared Library Names '' in http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html , this may help you understand the naming method of share library.

Every shared library has a special
name called the soname''. The soname
has the prefix
lib'', the name of
the library, the phrase .so'',
followed by a period and a version
number that is incremented whenever
the interface changes (as a special
exception, the lowest-level C
libraries don't start with
lib''). A
fully-qualified soname includes as a
prefix the directory it's in; on a
working system a fully-qualified
soname is simply a symbolic link to
the shared library's ``real name''.

Every shared library also has a ``real
name'', which is the filename
containing the actual library code.
The real name adds to the soname a
period, a minor number, another
period, and the release number. The
last period and release number are
optional. The minor number and release
number support configuration control
by letting you know exactly what
version(s) of the library are
installed. Note that these numbers
might not be the same as the numbers
used to describe the library in
documentation, although that does make
things easier.

In addition, there's the name that the
compiler uses when requesting a
library, (I'll call it the ``linker
name''), which is simply the soname
without any version number.

南烟 2024-10-16 20:56:25

不用担心libpython2.6的SO版本增加。永远不会增加; 2.6 不会有任何进一步的错误修复版本,即使有,SO 版本也不会增加。

您应该担心 libpython2.6 在系统的未来版本中消失(被 libpython2.7 取代)。目前还没有什么好的解决方案;使用 PEP 384,您将能够链接到 libpython3.so。

Don't worry about the SO version of libpython2.6 increasing. It will never increase; there won't be any further bugfix releases to 2.6, and even if there were, the SO version would not be increased.

You should rather worry about libpython2.6 going away in future releases of the system (to be replaced by libpython2.7). There isn't any good solution to that, yet; with PEP 384, you will be able to link with libpython3.so.

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