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 encouragesoftware reuse in amodular fashion. Libraries can use other libraries resulting in a hierarchy of libraries in a program.
When writing code that uses a library, aprogrammer only needs to know how to use it – not its internal details. For example, a program could use a library thatabstracts a complicatedsystem call so that the programmer can use the system feature without spending time to learn the intricacies of the system function.
The idea of a computer library dates back to the first computers created byCharles Babbage. An 1888 paper on hisAnalytical Engine suggested that computer operations could be punched on separate cards from numerical input. If these operation punch cards were saved for reuse then "by degrees the engine would have a library of its own."[1]
A woman working next to a filing cabinet containing the subroutine library on reels of punched tape for the EDSAC computer.
In 1947Goldstine andvon Neumann speculated that it would be useful to create a "library" ofsubroutines for their work on theIAS machine, an early computer that was not yet operational at that time.[2] They envisioned a physical library ofmagnetic wire recordings, with each wire storing reusable computer code.[3]
Inspired by von Neumann,Wilkes and his team constructedEDSAC. Afiling cabinet ofpunched tape held the subroutine library for this computer.[4] Programs for EDSAC consisted of a main program and a sequence of subroutines copied from the subroutine library.[5] 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.[6]
COBOL included "primitive capabilities for a library system" in 1959,[7] butJean Sammet described them as "inadequate library facilities" in retrospect.[8]
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 thesubprogram innovation ofFORTRAN. FORTRAN subprograms can be compiled independently of each other, but the compiler lacked alinker. So prior to the introduction of modules in Fortran-90,type checking between FORTRAN[NB 1] subprograms was impossible.[9]
By the mid 1960s, copy and macro libraries for assemblers were common. Starting with the popularity of theIBM System/360, libraries containing other types of text elements, e.g., system parameters, also became common.
Thelinking (orbinding) process resolves references known assymbols (orlinks) by searching for them in various locations including configured libraries. If alinker (or binder) does not find a symbol, then it fails, but multiple matches may or may not cause failure.
Static linking is linking atbuild time, such that the library executable code is included in the program.Dynamic linking is linking atrun time; it involves building the program with information that supports run-time linking to a dynamic link library (DLL). For dynamic linking, a compatible DLL file must be available to the program at run time, but for static linking, the program is standalone.
Smart linking is performed by a build tool that excludes unused code in the linking process. For example, a program that only uses integers for arithmetic, or does no arithmetic operations at all, can exclude floating-point library routines. This can lead to smaller program file size and reduced memory usage.
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 theloader. 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.
An executable library consists of code that has been converted from source code intomachine code or an intermediate form such asbytecode. A linker allows for using library objects by associating each reference with an address at which the object is located. For example, inC, a library function is invoked via C's normal function callsyntax andsemantics.[12]
A variant is a library containing compiled code (object code in IBM's nomenclature) in a form that cannot be loaded by the OS but that can be read by the linker.
Astatic library is an executable library that is linked into a program at build-time by a linker (or whatever the build tool is called that does linking).[13][14] This process, and the resulting stand-alone file, is known as astatic build of the program. A static build may not need any furtherrelocation ifvirtual memory is used and noaddress space layout randomization is desired.[15]
A static library is sometimes called anarchive on Unix-like systems.
Although generally an obsolete technology today, an object library exposes resources forobject-oriented programming (OOP) and a distributed object is a remote object library. Examples include:COM/DCOM,SOM/DSOM,DOE,PDO and variousCORBA-based systems.
The object library technology was developed since as OOP became popular, it became apparent that OOP runtime binding required information than contemporary libraries did not provide. In addition to the names and entry points of the code located within, due to inheritance, OOP binding also requires a list of dependencies – since the full definition of a method may be in different places. Further, this requires more than listing that one library requires the services of another. In OOP, the libraries themselves may not be known atcompile time, and vary from system to system.
The remote object technology was developed in parallel to support multi-tier programs with auser interface application running on apersonal computer (PC) using services of amainframe orminicomputer such as data storage and processing. For instance, a program on a PC would send messages to a minicomputer viaremote procedure call (RPC) to retrieve relatively small samples from a relatively large dataset. In response, distributed object technology was developed.
A class library containsclasses that can be used to createobjects. InJava, for example, classes are contained inJAR files and objects are created at runtime from the classes. However, inSmalltalk, a class library is the starting point for asystem image that includes the entire state of the environment, classes and all instantiated objects. Most class libraries are stored in apackage repository (such as Maven Central for Java). Client code explicitly specifies dependencies to external libraries in build configuration files (such as a Maven Pom in Java).
A remote library runs on another computer and its assets are accessed viaremote procedure call (RPC) over a network. Thisdistributed architecture allows for minimizing installation of the library and support for it on each consuming system and ensuring consistent versioning. A significant downside is that each library call entails significantly more overhead than for a local library.
A code generation library has a high-levelAPI generating or transformingbyte code forJava. They are used byaspect-oriented programming, some data access frameworks, and for testing to generate dynamic proxy objects. They also are used to intercept field access.[19]
On most modernUnix-like systems, library files are stored in directories such as/lib,/usr/lib and/usr/local/lib. A filename typically starts withlib, and ends with.a for a static library (archive) or.so for a shared object (dynamically linked library). For example,libfoo.a andlibfoo.so.
Often,symbolic link files are used to manage versioning of a library by providing a link file named without a version that links to a file named with a version. For example,libfoo.so.2 might be version 2 of libraryfoo and a link file namedlibfoo.so provides a version independent name to that file that programs link to. The link file could be changed to a refer to a version 3 (libfoo.so.3) such that consuming programs will then use version 3 without having to change the program.
Files with extension.la arelibtool archives; not usable by the system.
ThemacOS system inherits static library conventions fromBSD, with the library stored in a.a file. It uses either.so or.dylib for dynamic libraries. Most libraries in macOS, however, consist of "frameworks", placed inside special directories called "bundles" which wrap the library's required files and metadata. For example, a framework calledAbc would be implemented in a bundle calledAbc.framework, withAbc.framework/Abc being either the dynamically linked library file or a symlink to the dynamically linked library file inAbc.framework/Versions/Current/Abc.
Often, aWindowsdynamic-link library (DLL) has the file extension.dll,[20] although sometimes different extensions are used to indicate general content, e.g..ocx for aOLE library.
A.lib file can be either a static library or contain the information needed to build an application that consumes the associated DLL. In the latter case, the associated DLL file must be present at runtime.
^Goldstine, Herman;von Neumann, John (1947). Planning and coding of problems for an electronic computing instrument (Report). Institute for Advanced Study. pp. 3,21–22.OCLC26239859.it will probably be very important to develop an extensive "library" of subroutines
^Wilkes, M. V. (1951)."The EDSAC Computer".1951 International Workshop on Managing Requirements Knowledge. 1951 International Workshop on Managing Requirements Knowledge. IEEE. p. 79.doi:10.1109/afips.1951.13.
^Deshpande, Prasad (2013).Metamorphic Detection Using Function Call Graph Analysis (Thesis). San Jose State University Library.doi:10.31979/etd.t9xm-ahsc.
^"Code Generation Library".Source Forge.Archived from the original on 2010-01-12. Retrieved2010-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.