Filed under: technotes
Every now and then I need to remind myself how naming and versioning work with dynamic libraries. First, their version numbers are entirely distinct from the package that contains them. In other words, tpl v1.4 is a package version, but the library it installs may be libtpl.so.0. The library name reflects its ABI (interface) version.
It can be helpful to understand why there are apparently several versions of a shared library in a directory. Let’s take a look at a fictitious libjunk and its associated files as we might see on Linux system in /usr/lib:
|
libjunk.so.5.1.1
|
“real name”
|
|
libjunk.so.5
|
“soname”
|
|
libjunk.so
|
“linker name”
|
- The real name
- This refers to the “real” library file produced by the C compiler (libjunk.so.5.1.1). The naming convention is .so.INTERFACE.MINOR[.RELEASE].
- The “soname”
- ldconfig made this file (libjunk.so.5) as a symlink to the real file. It made the filename from the soname stored inside the real library (objdump –p libjunk.so.5.1.1 | grep SONAME). This soname was fixed at compilation time (gcc –shared –Wl,-soname,libjunk.so.5) –o libjunk.so.5.1.1 junk.c). This soname is recorded in binaries that depend on it, as can be seen using ldd.
- The “linker name”
- This file (libjunk.so) is used only for compiling and linking programs against the shared library. This is what the linker looks for when you specify –ljunk. It may just be a symlink to the soname. The newly linked object will record a dependency on the soname, not the real name. This permits new ABI-compatible versions of the library to be installed and used to satisfy the soname dependency.
The “soname” only needs to change when the library interface (ABI) changes in an incompatible way. Otherwise the soname can be left alone. New minor versions of the library can be installed and ldconfig will symlink the soname to the new minor version.
Setting the version under libtool
In tpl, the version numbers are passed to libtool via this line in Makefile.am:
libtpl_la_LDFLAGS = -no-undefined -version-info 1:0:0
The version string (1:0:0) is documented as current[:revision[:age]]. Only current is required and it is what we call INTERFACE version above.
Related links
- http://www.netfort.gr.jp/~dancer/column/libpkg-guide/libpkg-guide.html
- http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
- http://wiki.linuxquestions.org/wiki/Library-related_Commands_and_Files
- http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
Leave a Comment so far
Leave a comment
