Static Library - Advantages and Disadvantages

Advantages and Disadvantages

There are several advantages to statically linking libraries with an executable instead of dynamically linking them. The most significant is that the application can be certain that all its libraries are present and that they are the correct version. This avoids dependency problems, known colloquially as DLL Hell or more generally dependency hell. Usually, static linking will result in a significant performance improvement. Static linking can also allow the application to be contained in a single executable file, simplifying distribution and installation.

With static linking, it is enough to include those parts of the library that are directly and indirectly referenced by the target executable (or target library). With dynamic libraries, the entire library is loaded, as it is not known in advance which functions will be invoked by applications. Whether this advantage is significant in practice depends on the structure of the library.

In static linking, the size of the executable becomes greater than in dynamic linking, as the library code is stored within the executable rather than in separate files. But if library files are counted as part of the application then the total size will be similar. On Microsoft Windows it is common to include the library files an application needs with the application. On Unix-like systems this is less common as package management systems can be used to ensure the correct library files are available. This allows the library files to be shared between many applications leading to space savings. It also allows the library to be updated to fix bugs and security flaws without updating the applications that use the library. In practice, many executables (especially those targeting Microsoft Windows) use both static and dynamic libraries.

Read more about this topic:  Static Library

Famous quotes containing the word advantages:

    For, the advantages which fashion values, are plants which thrive in very confined localities, in a few streets, namely. Out of this precinct, they go for nothing; are of no use in the farm, in the forest, in the market, in war, in the nuptial society, in the literary or scientific circle, at sea, in friendship, in the heaven of thought or virtue.
    Ralph Waldo Emerson (1803–1882)