Historically, all library linking was static, but today
dynamic linking is an alternative and entails inherent trade-offs. An advantage of static over dynamic is that the application is guaranteed to have the library routines it requires available at run-time, as the code to those routines is embedded in the executable file. With dynamic linking, not only might the library file be missing, but even if found, it could be an incompatible version. Static avoids
DLL Hell or more generally
dependency hell and therefore can simplify development, distribution and installation. With static linking, a smart linker only includes the code that is actually used, but for a dynamic library, the entire library is loaded into the address space, which means that code that is not used by the program may be loaded into memory. However, if more than one program is using that code, only one copy of the shared code is loaded into memory. The size of an executable is larger with static linking than dynamic, as the statically-linked executable includes copies of library routines used by the program. However, if the size of an application is measured as the sum of the executable and its dynamic libraries, then the overall size is generally less for static linking. But if the same dynamic library is used by multiple applications, then the overall size of the combined applications and the dynamic libraries might be less with dynamic linking. A common practice on
Windows is to install a program's dynamic libraries with the program file. On
Unix-like systems this is less common as
package management systems can be used to ensure the correct library files are available in a shared location. Library files can be shared between applications. This can save space. The library can be updated to fix bugs and security flaws without updating each application that uses the library. But shared, dynamic libraries leads to the risk of dependency problems. In practice, many executables use both static and dynamic libraries. ==Linking and loading==