846 Chapter 41
Typically, the linker name is created in the same directory as the file to which it
refers. It can be linked either to the real name or to the soname of the most recent
major version of the library. Usually, a link to the soname is preferable, so that changes
to the soname are automatically reflected in the linker name. (In Section 41.7, we’ll see
that the ldconfig program automates the task of keeping sonames up to date, and
thus implicitly maintains linker names if we use the convention just described.)
If we want to link a program against an older major version of a shared library,
we can’t use the linker name. Instead, as part of the link command, we would
need to indicate the required (major) version by specifying a particular real
name or soname.
The following are some examples of linker names:
libdemo.so -> libdemo.so.2
libreadline.so -> libreadline.so.5
Table 41-1 summarizes information about the shared library real name, soname,
and linker name, and Figure 41-3 portrays the relationship between these names.
Figure 41-3: Conventional arrangement of shared library names
Creating a shared library using standard conventions
Putting all of the above information together, we now show how to build our demon-
stration library following the standard conventions. First, we create the object files:
$ gcc -g -c -fPIC -Wall mod1.c mod2.c mod3.c
Then we create the shared library with the real name libdemo.so.1.0.1 and the
soname libdemo.so.1.
Table 41-1: Summary of shared library names
Name Format Description
real name libname.so.maj.min File holding library code; one instance per major-
plus-minor version of the library.
soname libname.so.maj One instance per major version of library;
embedded in executable at link time; used at run
time to find library via a symbolic link with same
name that points to corresponding (most up-to-
date) real name.
linker name libname.so Symbolic link to latest real name or (more usually)
latest soname; single instance; allows construction
of version-independent link commands.
libname.so.maj.min
real name
(regular file)
Object code for
library modules
(symbolic link)
libname.so.maj.min
(symbolic link)
libname.so.maj
libname.so.maj
soname
libname.so
linker name