Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Although it is almost always preferable to use shared libraries, there are occasional situations where static libraries may be appropriate. In particular, the fact that a statically linked application contains all of the code that it requires at run time can be advantageous. For example, static linking is useful if the user can’t, or doesn’t wish to, install a shared library on the system where the program is to be used, or if the program is to be run in an environment (perhaps a chroot jail, for example) where shared libraries are unavailable. In addition, even a compatible shared library upgrade may unintentionally introduce a bug that breaks an application. By linking an application statically, we can ensure that it is immune to changes in the shared libraries on a system and that it has all of the code it requires to run (at the expense of a larger program size, and consequent increased disk and memory requirements).
By default, where the linker has a choice of a shared and a static library of the same name (e.g., we link using -Lsomedir -ldemo, and both libdemo.so and libdemo.a exist), the shared version of the library is used. To force usage of the static version of the library, we may do one of the following: