Static library

From Wikipedia, the free encyclopedia

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. This executable and the process of compiling it are both known as a static build of the program. Historically, libraries could only be static.

Static libraries are either merged with other static libraries and object files during building/linking to form a single executable, or they may be loaded at run-time into the address space of the loaded executable at a static memory offset determined at compile-time/link-time.

When static libraries are used to create an executable, its size will be large when compared to an executable which uses dynamic libraries. This is because linking to static libraries includes the actual code for the library function(s)/procedure(s) with the executable, whether linked at compile-time or at run-time. However, in some cases, linking to static libraries can result in a performance improvement over linking to dynamic libraries; linking to static libraries has also been used to resolve so-called "DLL hell" problems in older versions of Microsoft Windows. But these advantages are not the sole consideration, and many executables (especially those targeting Microsoft Windows) use both static and dynamic libraries.

It is important to note that any static library function can call a function or procedure in another static library. The linker/linking loader/loader handles this the same way as for any "normal" object file.

Static library files may also be linked/loaded at run-time by a linker or linking loader (e.g., the X11 module loader). However, whether such a process can be called static linking is controversial.

[edit] Creating static libraries in C/C++

Static libraries can be easily created in C or in C++. These two languages provide storage-class specifiers for indicating external or internal linkage, in addition to providing other features.

To create such a library, the exported functions/procedures and other objects variables must be specified for external linkage specified (e.g. not use the C static keyword).

See The C Book - Linkage for more information.

[edit] See also

Languages