How do applications resolve to different versions of shared libraries at run time?

Viewed 16993

I'm a noob to how shared libraries work on linux. I am trying to understand how do applications resolve different revisions of the same shared library at run-time on linux.

As far as I understand, a shared library has three "names", for example,

  1. libmy.so.1.2 (real-name i.e. the actual obj file)
  2. libmy.so.1 (SONAME, which is embedded in the actual obj file)
  3. libmy.so (linker name, provided to the linker at link time and embedded in executable)

When you install the library via LDCONFIG, it will create the following symbolic links

  • (2) => (1)
  • (3) => (2)

Now lets say I compile another version of the same library with the following real-name, libmy.so.2.0. The SONAME by guidelines would be libmy.so.2.0

At application link time what is the linker name that I would provide with the "-l" flag. Following the guidelines I read (http://www.dwheeler.com/program-library/Program-Library-HOWTO/x36.html), wouldn't it have to be libmy.so and if so, how will both versions of the obj file be distinguished ?

4 Answers

A complement to @paxdiablo's answer bullet one:

ldconfig doesn't set up the linker names; typically this is done during library installation, and the linker name is simply created as a symbolic link to the ``latest'' soname or the latest real name.

it means xxx.so will link to a latest minor version of the latest major version dynamic library file.

I think this explains why:

  • Those linking with xyz.so will get the latest minor version of the latest major version.

But I don't know how installation setup linker name and which tool make it(apt-get?)

  1. Libs have different versions in the name.
  2. Packages with name "lib" have only libs and have different versions in the name.
  3. System will compile only with the latest library, unless you define a different one.
  4. The application uses only those libraries that it needs. Check ldd , readelf.
  5. Apps contain a link .so and .pc file, check rpm system for what. https://fedoraproject.org/wiki/Packaging:Guidelines?rd=Packaging#Devel_Packages
Related