876 Chapter 42
that was current when the application was statically linked against the library.) This
technique provides an alternative to the traditional library versioning approach of
using major and minor version numbers in the shared library real name.
Defining initialization and finalization functions within a shared library allows
us to automatically execute code when the library is loaded and unloaded.
The LD_PRELOAD environment variable allows us to preload shared libraries.
Using this mechanism, we can selectively override functions and other symbols that
the dynamic linker would normally find in other shared libraries.
We can assign various values to the LD_DEBUG environment variable in order to
monitor the operation of the dynamic linker.
Further information
Refer to the sources of further information listed in Section 41.14.
42.8 Exercises
42-1. Write a program to verify that if a library is closed with dlclose(), it is not unloaded if
any of its symbols are used by another library.
42-2. Add a dladdr() call to the program in Listing 42-1 (dynload.c) in order to retrieve
information about the address returned by dlsym(). Print out the values of the fields
of the returned Dl_info structure, and verify that they are as expected.