Encyclopedia > Library linking

  Article Content

Library linking

Library linking describes the inclusion of one or more libraries of procedures into a new program. There are multiple types of linking: static linking and dynamic linking. These are described below.

Static Linking

Static linking is linking in which a library is embedded into the program executable at compile time[?] by a linker. A linker is a separate utility which takes one or more libraries and object files[?] (which are previously generated by a compiler or an assembler) and produces an actual executable file[?].

One of the biggest disadvantages of static linking is that the resulting executable file becomes larger and therefore consumes a larger amount of system resources and takes longer to load into memory.

Examples of libraries which are traditionally designed to be statically linked include the ANSI C standard library and the ALIB assembler library[?].

Dynamic Linking

Dynamic linking is linking in which a library is loaded by the operating system's loader[?] separately from the executable file at loadtime[?] or runtime.

Most operating systems resolve external dependencies like libraries (called imports) as part of the loading process. For these systems, the executables contain a table called an import directory which is a variable-length array of imports. Each element in the array contains a name of a library. The loader searches the hard disk for the needed library, loads it into memory at an unpredictable location and updates the executable with the library's location in memory. The executable then uses this information to call functions and access data stored in the library. This type of dynamic linking is called loadtime linking and is used by most operating systems including Windows and Linux. Loadtime linking is one of the most complex routines the loader performs while loading an application.

Other operating systems resolve dependencies at runtime. For these systems, the executable calls an operating system API, passing it the name of a library file, a function number within the library and the function's parameters. The operating system resolves the import immediately and calls the appropriate function on behalf of the application. This type of dynamic linking is called runtime linking. Because of the overhead added to each call, runtime linking is incredibly slow and negatively affects an executable's performance. As a result, runtime linking is rarely used by modern operating systems.

In dynamic linking the library, commonly referred to as a dynamic link library (DLL) or shared library, is a pre-compiled and linked executable file which is stored separately on the computer's hard disk. It is loaded only when needed by an application. In most cases, multiple applications can use the same copy of the library at the same time and there is no need for the operating system to load multiple instances of the library into memory concurrently. In these cases, the libraries are stateless. That is, any data which must be stored by the library is stored by the application(s) it is serving. For this reason, these dynamic libraries are considered in-process.

One of the largest disadvantages of dynamic linking is that the executables depend on the separately stored libraries in order to function properly. If the library is deleted, moved, renamed or replaced with an incompatible version, the executable could malfunction. This is commonly known as DLL-hell.

All Windows *.DLL files are dynamically linked libraries.

All Wikipedia text is available under the terms of the GNU Free Documentation License

  Search Encyclopedia

Search over one million articles, find something about almost anything!
  Featured Article
Dennis Gabor

...     Contents Dennis Gabor Dennis Gabor (Gábor Dénes) (1900-1979) was a Hungarian physicist. He invented holography in 1947, for ...

This page was created in 39 ms