C++ Programming/Compiler/Linker/Libraries/Static and Dynamic Libraries

Static and Dynamic Libraries

edit
 

To do:
define "static library" and "dynamic library" and "static binary" here


Advantages of using static binaries:

  • Simplification of program distribution (fewer files).
  • Code simplification (no version checks as required in dynamic libraries).
  • Will only compile the code that is used.

Disadvantages of using static binaries:

  • Waste of resources: Generates larger binaries, since the library is compiled into the executable. Wastes memory as the library cannot be shared (in memory) between processes (depending on the operating system).
  • Program will not benefit from bug fixes or extensions in the libraries without being recompiled.
Binary/Source Compatibility of libraries

A library is said to be binary compatible if the program that dynamically links to an earlier version of that library, continues to work using another versions of the same library. If a recompilation of the program is needed for it to run with each new version the library is said to be source compatible.

Producing binary compatible libraries is beneficial for distribution but harder to maintain by the programmer. It is often seen as a better solution to do static linking, if the library is only source compatible, since it will not cause problems to the end-user.

Binary compatibility saves a lot of trouble and is a signal that the library reached a status of stability. It makes it easier to distribute software for a certain platform. Without ensuring binary compatibility between releases, people will be forced to offer statically linked binaries.