Monday, March 26, 2018

Linux library naming conventions

[root@localhost lib]# ls -lrt |grep libodbc.so
-rwxr-xr-x 1 root root 1804447 May 29  2013 libodbc.so.2.0.0
lrwxrwxrwx 1 root root      16 Nov  6  2014 libodbc.so.2 -> libodbc.so.2.0.0
lrwxrwxrwx 1 root root      16 Nov  6  2014 libodbc.so -> libodbc.so.2.0.0

Real name:  libodbc.so.2.0.0
SONAME: libodbc.so.2 
Linker name: libodbc.so

gcc "-lodbc" will seek for libodbc.so(a link or a file).
The depended library is the SONAME: libodbc.so.2


Print SONAME of a shared library:
[root@localhost lib]# objdump -p libodbc.so |grep  'SONAME' |awk -F ' '  '{print $2}'
libodbc.so.2

[root@localhost lib]# readelf -d libodbc.so |grep soname
 0x000000000000000e (SONAME)             Library soname: [libodbc.so.2]

Reference:
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.

More: 
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html


No comments: