8.2. Shared Libraries
Shared libraries have several advantages over static libraries:
Linux shares the memory used for executable code among all the processes that use the shared library, so whenever you have more than one program using the same code, it is to your advantage, and to your users' advantage, to put the code in a shared library.
Because shared libraries save system memory, they can make the whole system work faster, especially in situations in which memory is not plentiful.
Because code in a shared library is not copied into the executable, only one copy of the library code resides on disk, saving both disk space and the computer's time spent copying the code from disk to memory when programs are run.
When bugs are found in a library, a shared library can be replaced by aversion that has the bugs fixed, instead of having to recompile every program that uses the library.
The cost exacted by these advantages is primarily complexity. The executable consists of several interdependent parts, and if you give a binary executable to someone who does not have a shared library that the executable requires, it will not run. A secondary cost is the time it takes when the program starts to find and load the shared libraries; this is generally negated because the shared libraries usually have already been loaded into memory for other processes, and so they do not have to be loaded from disk again when the new process is started.
Linux originally used a simplistic binary file format (actually, three variations on a simplistic binary file format) that made the process of creating shared libraries difficult and time-consuming. Once created, the libraries could not be easily extended in a backward-compatible way. The author of the library had to leave space for data structure expansion by hand-editing tables, and even that did not always work.
Now, the standard binary file format on almost every Linux platform is the modern, extensible Executable and Linking Format (ELF) file format. This means that on practically all Linux platforms, the steps you take to create and use shared libraries are exactly the same.
 See Understanding ELF Object Files and Debugging Tools [Nohr, 1994] or ftp://tsx-11.mit.edu/pub/linux/packages/GCC/ELF.doc.tar.gz for detailed information on the ELF format. The Linux-specifix details are covered in the document ftp://tsx-11.mit.edu/pub/linux/packages/GCC/elf.ps.gz.