Shared Libraries

written by: Lorent Konenbal; article published: year 2007, month 07;


In: Root » Computers and technology » Linux » Shared Libraries

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

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.

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article