linux - 链接符号链接(symbolic link)而不是soname

标签 linux elf dynamic-linking

我有一个 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,我认为我应该安全地链接到库的更通用的版本名称。

最佳答案

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

Every shared library has a special name called the soname''. The soname has the prefixlib'', 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 withlib''). 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.

关于linux - 链接符号链接(symbolic link)而不是soname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4561871/

相关文章:

linux - 如何删除 DNS、bind9 中的查询 "NULL"和 "WKS"?

c++ - 如何从 Linux 中的 C++ 程序调用 so 文件中存在的类及其函数

c++ - linux交叉编译和动态库/链接

C++。将 .dll 文件链接到项目

c - 使用 malloc.c 的堆分配内存边界

linux - 如何在没有完整路径的情况下在文件夹和父文件夹之间复制

php - 无法从 vagrant VM 发出出站 HTTP 请求

java - Linux native 可执行文件不包含正确的符号信息

elf - 在 ELF 文件中,_start 的地址是如何确定的?

C++构造函数问题(linux)