Library (computing)
In computer science, a library is a collection of read-only resources that is leveraged during software development to implement a computer program.
Historically, a library consisted of
For example, a program could use a library to indirectly make system calls instead of making those system calls directly in the program.
Characteristics
General
A library can be used by multiple, independent consumers (programs and other libraries). This differs from resources defined in a program which can usually only be used by that program.
When a consumer uses a library resource, it gains the value of the library without having to implement it itself. Libraries encourage code reuse in a modular fashion.
When writing code that uses a library, a programmer only needs to know high-level information such as what items it contains at and how to use the items – not all of the internal details of the library.
Libraries can use other libraries resulting in a hierarchy of libraries in a program.
Executable
A library of executable code has a well-defined interface by which the functionality is invoked. For example, in C, a library function is invoked via C's normal function call capability. The linker generates code to call a function via the library mechanism if the function is available from a library instead of from the program itself.[1]
The functions of a library can be connected to the invoking program at different
Most compiled languages have a standard library, although programmers can also create their own custom libraries. Most modern software systems provide libraries that implement the majority of the system services. Such libraries have organized the services which a modern application requires. As such, most code used by modern applications is provided in these system libraries.
History
The idea of a computer library dates back to the first computers created by
In 1947
Inspired by von Neumann, Wilkes and his team constructed EDSAC. A filing cabinet of punched tape held the subroutine library for this computer.[6] Programs for EDSAC consisted of a main program and a sequence of subroutines copied from the subroutine library.[7] In 1951 the team published the first textbook on programming, The Preparation of Programs for an Electronic Digital Computer, which detailed the creation and the purpose of the library.[8]
COBOL included "primitive capabilities for a library system" in 1959,[9] but Jean Sammet described them as "inadequate library facilities" in retrospect.[10]
JOVIAL has a Communication Pool (COMPOOL), roughly a library of header files.
Another major contributor to the modern library concept came in the form of the
By the mid 1960s, copy and macro libraries for assemblers were common. Starting with the popularity of the IBM System/360, libraries containing other types of text elements, e.g., system parameters, also became common.
In IBM's OS/360 and its successors this is called a partitioned data set.
The first
Linking
Libraries are important in the program linking or binding process, which resolves references known as links or symbols to library modules. The linking process is usually automatically done by a
The references being resolved may be addresses for jumps and other routine calls. They may be in the main program, or in one module depending upon another. They are resolved into fixed or relocatable addresses (from a common base) by allocating runtime memory for the
Some programming languages use a feature called smart linking whereby the linker is aware of or integrated with the compiler, such that the linker knows how external references are used, and code in a library that is never actually used, even though internally referenced, can be discarded from the compiled application. For example, a program that only uses integers for arithmetic, or does no arithmetic operations at all, can exclude floating-point library routines. This smart-linking feature can lead to smaller application file sizes and reduced memory usage.
Relocation
Some references in a program or library module are stored in a relative or symbolic form which cannot be resolved until all code and libraries are assigned final static addresses. Relocation is the process of adjusting these references, and is done either by the linker or the loader. In general, relocation cannot be done to individual libraries themselves because the addresses in memory may vary depending on the program using them and other libraries they are combined with. Position-independent code avoids references to absolute addresses and therefore does not require relocation.
Static libraries
When linking is performed during the creation of an executable or another object file, it is known as static linking or early binding. In this case, the linking is usually done by a linker, but may also be done by the compiler.[14] A static library, also known as an archive, is one intended to be statically linked. Originally, only static libraries existed. Static linking must be performed when any modules are recompiled.
All of the modules required by a program are sometimes statically linked and copied into the executable file. This process, and the resulting stand-alone file, is known as a
Shared libraries
A shared library or shared object is a file that is intended to be shared by
Shared libraries can be statically linked during compile-time, meaning that references to the library modules are resolved and the modules are allocated memory when the executable file is created.[citation needed] But often linking of shared libraries is postponed until they are loaded.[dubious – discuss]
Object libraries
Although originally pioneered in the 1960s, dynamic linking did not reach the most commonly-used operating systems until the late 1980s. It was generally available in some form in most operating systems by the early 1990s. During this same period, object-oriented programming (OOP) was becoming a significant part of the programming landscape. OOP with runtime binding requires additional information that traditional libraries do not supply. In addition to the names and entry points of the code located within, they also require a list of the objects they depend on. This is a side-effect of one of OOP's core concepts, inheritance, which means that parts of the complete definition of any method may be in different places. This is more than simply listing that one library requires the services of another: in a true OOP system, the libraries themselves may not be known at compile time, and vary from system to system.
At the same time many developers worked on the idea of multi-tier programs, in which a "display" running on a desktop computer would use the services of a mainframe or minicomputer for data storage or processing. For instance, a program on a GUI-based computer would send messages to a minicomputer to return small samples of a huge dataset for display. Remote procedure calls (RPC) already handled these tasks, but there was no standard RPC system.
Soon the majority of the minicomputer and mainframe vendors instigated projects to combine the two, producing an OOP library format that could be used anywhere. Such systems were known as object libraries, or distributed objects, if they supported remote access (not all did). Microsoft's COM is an example of such a system for local use. DCOM, a modified version of COM, supports remote access.
For some time object libraries held the status of the "next big thing" in the programming world. There were a number of efforts to create systems that would run across platforms, and companies competed to try to get developers locked into their own system. Examples include
Class libraries
Class libraries are the rough OOP equivalent of older types of code libraries. They contain
Today most class libraries are stored in a
Remote libraries
Another library technique uses completely separate executables (often in some lightweight form) and calls them using a remote procedure call (RPC) over a network to another computer. This maximizes operating system re-use: the code needed to support the library is the same code being used to provide application support and security for every other program. Additionally, such systems do not require the library to exist on the same machine, but can forward the requests over the network.
However, such an approach means that every library call requires a considerable amount of overhead. RPC calls are much more expensive than calling a shared library that has already been loaded on the same machine. This approach is commonly used in a
Code generation libraries
Code generation libraries are high-level
File naming
Most modern Unix-like systems
The system stores libfoo.a
and libfoo.so
files in directories such as /lib
, /usr/lib
or /usr/local/lib
. The filenames always start with lib
, and end with a suffix of .a
(
macOS
The system inherits static library conventions from
.a
file, and can use .so
-style dynamically linked libraries (with the .dylib
suffix instead). Most libraries in macOS, however, consist of "frameworks", placed inside special directories called "bundlesMyFramework
would be implemented in a bundle called MyFramework.framework
, with MyFramework.framework/MyFramework
being either the dynamically linked library file or being a symlink to the dynamically linked library file in MyFramework.framework/Versions/Current/MyFramework
.
Microsoft Windows
.LIB
file in Windows.DLL
file must be present at runtime.
See also
- Code reuse – Use of existing software to build new software
- Linker (computing) – Computer program which combines multiple object files into a single file
- Loader (computing) – Part of an operating system
- Dynamic-link library – Microsoft's implementation of the shared library concept in Windows and OS/2
- Object file – File containing relocatable format machine code
- Plug-in – Software component that adds a specific feature to an existing software application
- Prelink, also known as Prebinding
- Static library – set of routines, external functions and variables in computer science
- Runtime library – Type of software library
- Visual Component Library – Object Pascal framework for Windows (VCL)
- Component Library for Cross Platform (CLX)
- C standard library – Standard library for the C programming language
- Java Class Library – standard library for Java and other JVM programming languages
- Framework Class Library – Standard library of Microsoft's .NET Framework
- Generic programming – Style of computer programming (used by the C++ Standard Library)
- soname – Field of data in a shared object file
- Method stub – Short and simple version of a method
Notes
- ^ It was possible earlier between, e.g., Ada subprograms.
References
- .
- ^ "Static Libraries". TLDP. Archived from the original on 2013-07-03. Retrieved 2013-10-03.
- ^ Babbage, H. P. (1888-09-12). "The Analytical Engine". Proceedings of the British Association. Bath.
- ISBN 978-1-4008-2013-9.
- OCLC 26239859.
it will probably be very important to develop an extensive "library" of subroutines
- .
- S2CID 20261972.
- OCLC 641145988.
- ISBN 0-12-745040-8.
- ^ Wexelblat, op. cit., p. 258
- ISBN 0-201-18483-4.
- ^ Wilson and Clark, op. cit., p. 52
- ^ Wexelblat, op. cit., p. 716
- ISBN 978-1-59749-237-9. Retrieved 2021-05-27.
- ^ Collberg, Christian; Hartman, John H.; Babu, Sridivya; Udupa, Sharath K. (2003). SLINKY: Static Linking Reloaded. USENIX '05. Department of Computer Science, University of Arizona. Archived from the original on 2016-03-23. Retrieved 2016-03-17.
- Source Forge. Archivedfrom the original on 2010-01-12. Retrieved 2010-03-03.
Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.
- ^
Bresnahan, Christine; Blum, Richard (2015-04-27). LPIC-1 Linux Professional Institute Certification Study Guide: Exam 101-400 and Exam 102-400. John Wiley & Sons (published 2015). p. 82. ISBN 9781119021186. Archivedfrom the original on 2015-09-24. Retrieved 2015-09-03.
Linux shared libraries are similar to the dynamic link libraries (DLLs) of Windows. Windows DLLs are usually identified by
.dll
filename extensions.
Further reading
- Article Beginner's Guide to Linkers by David Drysdale
- Article Faster C++ program startups by improving runtime linking efficiency by Léon Bottou and John Ryland
- How to Create Program Libraries by Baris Simsek
- BFD - the Binary File Descriptor Library
- 1st Library-Centric Software Design Workshop LCSD'05 Archived 2019-08-28 at the Wayback Machine at OOPSLA'05
- 2nd Library-Centric Software Design Workshop LCSD'06 at OOPSLA'06
- How to create shared library by Ulrich Drepper (with much background info)
- Anatomy of Linux dynamic libraries at IBM.com