144 Chapter 5
Creating and Using Libraries
Creating Shared Libraries
libP → libA → libD → libQ → libB → <current search list>
Updating a Shared Library
The ld command cannot replace or delete object modules in a shared
library. Therefore, to update a shared library, you must relink the library
with all the object files you want the library to include. For example,
suppose you fix some routines in length.c (from the previous section)
that were giving incorrect results. To update the libunits.sl library to
include these changes, you would use this series of commands:
$ cc -Aa -c +z length.c
$ ld -b -o libunits.sl length.o volume.o mass.o
Any programs that use this library will now be using the new versions of
the routines. That is, you do not have to relink any programs that use this
shared library. This is because the routines in the library are attached to
the program at run time.
This is one of the advantages of shared libraries over archive libraries: if
you change an archive library, you must relink any programs that use
the archive library. With shared libraries, you need only recreate the
library.
Incompatible Changes to a Shared Library
If you make incompatible changes to a shared library, you can use library
versioning to provide both the old and the new routines to ensure that
programs linked with the old routines continue to work. See “Version
Control with Shared Libraries” for more information on version control
of shared libraries.
Shared Library Location
You can place shared libraries in the same locations as archive libraries
(see “Archive Library Location”). Again, this is typically
/usr/local/lib and /usr/contrib/lib (32-bit mode) or
/user/local/lib/pa20_64 and /usr/contrib/lib/pa20_64 (64
bit mode) for application libraries, and /usr/lib (32-bit mode) or
/user/lib/pa20_64 (64-bit mode) for system libraries. However, these
are just suggestions.