Shared Library sonames, Real Names and Linker Names
A shared library has three names: the linker name used at build time, the soname recorded in binaries and the real name of the file. See how they fit together.

Look in /usr/lib/x86_64-linux-gnu and you will find a pattern: libz.so, libz.so.1 and libz.so.1.3.1, usually three names for one file. The first is a symbolic link, the second is a symbolic link, and the third is the file itself. This is not clutter. Each name is used by a different tool at a different time, and the arrangement lets you upgrade a library without rebuilding the programs that use it, while stopping an incompatible version from being picked up by accident. This post names the three, shows who uses each, and builds a small library to demonstrate the whole chain. It uses GCC 14 and GNU binutils 2.42 on Linux x86-64. The convention is described in the Linux Documentation Project shared library guide and enforced by ld.so, documented in ld.so(8).
The three names
The real name is the actual file, with the full version: libvec.so.1.2.3. It holds the code. The numbers are major, minor and patch.
The soname, short for shared object name, is libvec.so.1. It carries only the major version. It is stored inside the library, in a dynamic entry called SONAME, and it is what programs record when they are linked against the library. It is the compatibility promise: every library with the soname libvec.so.1 offers the same interface to programs built for libvec.so.1. When the interface breaks, the major number goes up and the soname changes.
The linker name is libvec.so, with no version. It is a symbolic link, used only at build time. When you write -lvec, the linker looks for libvec.so, follows it to the real file, reads the soname from it, and records the soname, not the file name, in the program.
What links to what
The arrangement on disk is a chain of links:
| Name | Kind | Points to | Used by |
|---|---|---|---|
libvec.so | symlink | libvec.so.1 | the linker at build time |
libvec.so.1 | symlink | libvec.so.1.2.3 | the dynamic loader at run time |
libvec.so.1.2.3 | real file | none | holds the code |
ldconfig creates the soname link for you from the SONAME inside each library. The linker name link is made by the package or by hand, and distributions often split it into a development package, so a machine that only runs programs has the soname links and no linker name.
Build one and watch the names
Write a library and build it with a real name and a soname:
double vec_dot(const double *a, const double *b, int n)
{
double sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i] * b[i];
}
return sum;
}gcc -O2 -fPIC -shared -Wl,-soname,libvec.so.1 -o libvec.so.1.2.3 vec.c
ln -s libvec.so.1.2.3 libvec.so.1
ln -s libvec.so.1 libvec.so
ls -l libvec*lrwxrwxrwx 1 dev dev 14 Nov 23 10:20 libvec.so -> libvec.so.1
lrwxrwxrwx 1 dev dev 16 Nov 23 10:20 libvec.so.1 -> libvec.so.1.2.3
-rwxr-xr-x 1 dev dev 15608 Nov 23 10:20 libvec.so.1.2.3Now read the soname back out of the real file:
readelf -d libvec.so.1.2.3 | grep SONAME 0x000000000000000e (SONAME) Library soname: [libvec.so.1]The soname inside the file is libvec.so.1, whatever the file is called on disk. The size and date are an example.
Link a program and see which name it records
#include <stdio.h>
double vec_dot(const double *a, const double *b, int n);
int main(void)
{
double a[] = {1, 2}, b[] = {3, 4};
printf("%.1f\n", vec_dot(a, b, 2));
return 0;
}gcc app.c -L. -lvec -o app
readelf -d app | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [libvec.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]The program asks for libvec.so.1. It does not mention libvec.so or libvec.so.1.2.3. That is the point of the soname. Install a patched libvec.so.1.2.4 and move the libvec.so.1 link to it, and the program picks up the fix on its next start without being rebuilt. Install libvec.so.2 with a changed interface alongside, and old programs still ask for .1 and are not affected.
What happens without a soname
If you build the library without -Wl,-soname, the library has no SONAME entry. Then the linker records the name it used to find the file, as given on the command line. Link with -L. -lvec and the program records libvec.so, the linker name, which is the wrong thing: the program now depends on an unversioned name, and the loader will accept any libvec.so on the search path, including an incompatible one. Link with a path, ./libvec.so.1.2.3, and the program records that path, which breaks when the file moves. You can see the damage:
gcc -O2 -fPIC -shared -o libbad.so vec.c
gcc app.c -L. -lbad -o app_bad
readelf -d app_bad | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [libbad.so]The recorded name is the unversioned one. Always set a soname when you build a shared library you intend to share.
Choosing the major number
The major number is a promise, so change it when the promise changes. Increment it when you remove a function, change a function's signature, change the layout of a structure that callers use, or change the meaning of a return value. Do not change it when you add a new function, fix a bug or tune performance, since callers built against the old version still work. Minor and patch numbers in the real name record those changes for people, and no tool checks them.
The mistake that hurts is a silent break: a structure grows a field, the soname stays, and old programs allocate the old size and crash somewhere inside the library. Design the public interface to prevent that, as covered in designing a stable C ABI for a shared library. For finer control within one major number, GNU symbol versioning lets one file export several versions of a function.
How ldconfig and the loader use it
ldconfig scans the library directories, reads each library's SONAME, creates the libvec.so.1 link and writes a cache, /etc/ld.so.cache. At run time the loader looks up libvec.so.1 in that cache, which is far quicker than scanning directories. Run ldconfig -p | grep libvec to see what the cache holds:
sudo ldconfig
ldconfig -p | grep libvec libvec.so.1 (libc6,x86-64) => /usr/local/lib/libvec.so.1If you install a library in a custom directory and the loader cannot find it, either add the directory to a file in /etc/ld.so.conf.d/ and rerun ldconfig, or set a runpath in the program. Without a cache entry or a path, the loader reports cannot open shared object file even though the file exists.
Reading the names on a real system
Check any system library the same way. Take the compression library that most distributions install, and follow its chain:
readlink -f /usr/lib/x86_64-linux-gnu/libz.so.1
readelf -d /usr/lib/x86_64-linux-gnu/libz.so.1 | grep SONAME/usr/lib/x86_64-linux-gnu/libz.so.1.3.1
0x000000000000000e (SONAME) Library soname: [libz.so.1]readlink -f follows every link and prints the real file, and readelf confirms the soname matches the link you started from. If a package manager reports a broken library after an upgrade, run these two commands: a soname that does not match its link name, or a link that points nowhere, is the whole diagnosis. The version numbers shown are an example for one distribution release.
When you ship your own library, add this chain to your install rule and check it in a test. Create the three names in one place, run ldconfig in the package's post-install step, and fail the build if readelf -d on the real file does not print the soname you meant. That one assertion prevents the leak of unversioned names into every program that links against you.


