How do SO (shared object) numbers work?

I’m aware that shared objects under Linux use “so numbers”, namely that different versions of a shared object are given different extensions, for example:


I understand the idea is to have two distinct files such that two versions of a library can exist on a system (as opposed to “DLL Hell” on Windows). I’d like to know how this works in practice? Often, I see that is in fact a symbolic link to where .2 is the latest version. How then does an application depending on an older version of identify it correctly? Are there any rules as to what numbers one must use? Or is this simply convention? Is it the case that, unlike in Windows where software binaries are transferred between systems, if a system has a newer version of a shared object it is linked to the older version automatically when compiling from source?

I suspect this is related to ldconfig but I’m not sure how.

Asked By: user119


Binaries themselves know which version of a shared library they depend on, and request it specifically. You can use ldd to show the dependencies; mine for ls are:

$ ldd /bin/ls =>  (0xb784e000) => /lib/ (0xb782c000) => /lib/ (0xb7824000) => /lib/ (0xb76dc000) => /lib/ (0xb76c3000)
    /lib/ (0xb784f000) => /lib/ (0xb76bd000)

As you can see, it points to e.g., not just

The reason for the symbolic link is for the linker. When you want to link against directly, you give gcc the flag -lpthread, and it adds on the lib prefix and .so suffix automatically. You can’t tell it to add on the .so.0 suffix, so the symbolic link points to the newest version of the lib to faciliate that

Answered By: Michael Mrozek

The numbers in the shared libraries are convention used in Linux to identify the API of a library. Typically the format is:

And as you noticed usually there is a symbolic link from to ldconfig is responsible for updating this link to the newest version.

The MAJOR is typically incremented when the API changes (new entry points are removed or the parameters or types changed). The MINOR typically is incremented for bug fix releases or when new APIs are introduced without breaking existing APIs.

A more extensive discussion can be found here: Dissecting shared libraries

Answered By: is the filename used by the compiler/linker when first looking for a library specified by -lNAME. Inside a shared library file is a field called the SONAME. This field is set when the library itself is first linked into a shared object (so) by the build process. This SONAME is actually what a linker stores in an executable depending on that shared object is linked with it. Normally the SONAME is in the form of and is changed anytime the library becomes incompatible with existing executables linked to it and both major versions of the library can be kept installed as needed (though only one will be pointed to for development as Also, to support easily upgrading between minor versions of a library, is normally a link to a file like A new minor version can be installed and once completed, the link to the old minor version is bumped to point to the new minor version immediately upgrading all new executions to use the upgraded library. Also, see my answer to Linux, GNU GCC, ld, version scripts and the ELF binary format — How does it work?

Answered By: penguin359

Shared libraries should be versioned according to the following scheme:


  • X = backwards incompatible ABI release
  • Y = backwards compatible ABI release
  • Z = Internal changes only – no change to the ABI

Typically you only see the first digit like because the first digit is the only thing needed to identify the “version” of the library since all the other digits are backwards compatible.

ldconfig maintains a table of what shared libraries are available on a system and where the path to that library exists. You can verify this by running:

ldconfig -p

When a package is built for something like Red Hat, the shared libraries being called out in the binary will be looked up and added as dependencies of the package at RPM build time. Therefore, when you go to install the package, the installer will look up whether or not is installed on the system by checking ldconfig.

You can see the dependencies of a package by doing something like:

rpm -qpR hello.rpm

This system (unlike Windows) allows for multiple versions of the to be installed on a system and be used by different applications at the same time.

Answered By: ascotan
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.