Library (computer science)
Encyclopedia
In computer science
, a library is a collection of resources used to develop software. These may include pre-written code
and subroutine
s, classes
, values
or type
specifications.
Libraries contain code and data that provide services to independent programs. This encourages the sharing and changing of code and data in a modular
fashion, and eases the distribution of the code and data. Some executable
s are both standalone programs and libraries, but most libraries are not executable. Executables and libraries make references known as links to each other through the process known as linking, which is typically done by a linker.
Most compiled languages have a standard library
although programmers can also create their own custom libraries. Most modern software system
s of 2009 provide libraries that implement the majority of system services. Such libraries have commoditized the services which a modern application requires. As such, most code used by modern applications is provided in these system libraries.
The GPL linking exception
allows programs which do not license themselves under GPL
to link to libraries licensed under the exception without thereby becoming subject to GPL requirements.
Libraries often contain a jump table of all the methods within it, known as entry points. Calls into the library use this table, looking up the location of the code in memory, then calling it. This introduces overhead in calling into the library, but the delay is so small as to be negligible.
definitions from the program implementation
. JOVIAL
brought the "COMPOOL" (Communication Pool) concept to popular attention in 1959, although it adopted the idea from the large-system SAGE
software. Following the computer science principles of separation of concerns
and information hiding
, "Comm Pool's purpose was to permit the sharing of System Data among many programs by providing a centralized data description."
COBOL
also included "primitive capabilities for a library system" in 1959, but Jean Sammet
described them as "inadequate library facilities" in retrospect.
Another major contributor to the modern library concept came in the form of the subprogram innovation of FORTRAN
. FORTRAN subprograms can be compiled independently of each other, but the compiler lacks a linker. So prior to the introduction of modules in Fortran-90, type checking between subprograms was impossible.
Finally, historians of the concept should remember the influential Simula 67. Simula was the first object-oriented programming
language, and its classes
are nearly identical to the modern concept as used in Java
, C++
, and C#. The class concept of Simula was also a progenitor of the package in Ada
and the module of Modula-2
. Even when developed originally in 1965, Simula classes could be included in library files and added at compile time.
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 memory segment
s of each module referenced.
Some programming languages may use a feature called smart linking wherein 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.
. 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.
. 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 static build
of the program. A static build may not need any further relocation
if virtual memory
is used and no address space layout randomization
is desired.
Shared libraries can be statically linked, meaning that references to the library modules are resolved and the modules are allocated memory when the executable file is created. But often linking of shared libraries is postponed until they are loaded.
Most modern operating system
s can have shared library files of the same format as the executable files. This offers two main advantages: first, it requires making only one loader for both of them, rather than two (having the single loader is considered well worth its added complexity). Secondly, it allows the executables also to be used as shared libraries, if they have a symbol table
. Typical combined executable and shared library formats are ELF
and Mach-O
(both in Unix) and PE
(Windows). In Windows, the concept was taken one step further, with even system resources such as fonts being bundled in the PE format. The same is true under OpenStep, where the universal "bundle" format is used for almost all system resources.
es as well as on disk. If virtual memory is used, processes execute the same physical page of RAM, mapped into the different address spaces of each process. This has advantages. For instance on the OpenStep
system, applications were often only a few hundred kilobytes in size and loaded quickly; the majority of their code was located in libraries that had already been loaded for other purposes by the operating system. There is a cost, however; shared code must be specifically written to run in a multitasking environment. In some older environments such as 16-bit Windows or MPE for the HP 3000, only stack based data (local) was allowed, or other significant restrictions were placed on writing a shared library.
Programs can accomplish RAM sharing by using position independent code as in Unix
, which leads to a complex but flexible architecture, or by using common virtual addresses as in Windows and OS/2
. These systems make sure, by various tricks like pre-mapping the address space and reserving slots for each shared library, that code has a great probability of being shared. A third alternative is single-level store
, as used by the IBM System/38 and its successors. This allows position-dependent code but places no significant restrictions on where code can be placed or how it can be shared.
In some cases different versions of shared libraries can cause problems, especially when libraries of different versions have the same file name, and different applications installed on a system each require a specific version. Such a scenario is known as DLL hell
, named after the Windows and OS/2 DLL file. Most modern operating systems after 2001, have clean-up methods to eliminate such situations.
or DLL under Windows and OS/2
; dynamic shared object or DSO under Unix-like
systems) is a library intended for dynamic linking. Only a minimum amount of work is done by the linker when the executable file is created; it only records what library routines the program needs and the index names or numbers of the routines in the library. The majority of the work of linking is done at the time the application is loaded (load time) or during execution (run time). The necessary linking program, called a dynamic linker or linking loader, is actually part of the underlying operating system
.
Programmers originally developed dynamic linking in the Multics
operating system, starting in 1964, and the MTS (Michigan Terminal System
), built in the late 1960s.
in Mac OS X and prelinking in Linux. Disadvantages of this technique include the time required to precompute these addresses every time the shared libraries change, the inability to use address space layout randomization
, and the requirement of sufficient virtual address space for use (a problem that will be alleviated by the adoption of 64-bit
architectures, at least for the time being).
If a shared library that an executable depends on is deleted, moved, or renamed, or if an incompatible version of the library is copied to a place that is earlier in the search, the executable would fail to load. On Windows this is commonly known as DLL hell
.
stores generic system libraries in a directory defined by the LIBS: path assignment. Application-specific libraries can go in the same directory as the application's executable. AmigaOS will search these locations when an executable attempts to launch a shared library. An application may also supply an explicit path when attempting to launch a library.
will check the registry
to determine the proper place to find an ActiveX
DLL, but for other DLLs it will check the directory from where it loaded the program; the current working directory; any directories set by calling the
. Applications written for the .NET Framework
framework (since 2002), also check the Global Assembly Cache
as the primary store of shared dll files to remove the issue of DLL hell
.
used a more flexible system, collecting a list of libraries from a number of known locations (similar to the PATH concept) when the system first starts. Moving libraries around causes no problems at all, although users incur a time cost when first starting the system.
systems have a "search path" specifying file system directories
in which to look for dynamic libraries. Some systems specify the default path in a configuration file
; others hard-code it into the dynamic loader. Some executable file
formats can specify additional directories in which to search for libraries for a particular program. This can usually be overridden with an environment variable
, although it is disabled for setuid
and setgid programs, so that a user can't force such a program to run arbitrary code with root permissions. Developers of libraries are encouraged to place their dynamic libraries in places in the default search path. On the downside, this can make installation of new libraries problematic, and these "known" locations quickly become home to an increasing number of library files, making management more complex.
or explicitly at run time. Implicit requests are made at compile time when a linker adds library references that include file paths or simply file names. Explicit requests are made when applications make direct calls to an operating system's API at run time.
Most operating systems that support dynamically linked libraries also support dynamically loading such libraries via a run-time linker API
. For instance, Microsoft Windows
uses the API functions LoadLibrary, LoadLibraryEx, FreeLibrary and GetProcAddress with Microsoft Dynamic Link Libraries; POSIX
based systems, including most UNIX and UNIX-like systems, use dlopen, dlclose and dlsym. Some development systems automate this process.
s used by consumers 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 don't supply. In addition to the names and entry points of the code located within, they also require a list of the objects on which they depend. This is a side-effect of one of OOP's main advantages, 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 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 that 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 IBM
's System Object Model
(SOM/DSOM), Sun Microsystems
' Distributed Objects Everywhere
(DOE), NeXT
's Portable Distributed Objects
(PDO), Digital
's ObjectBroker
, Microsoft's Component Object Model
(COM/DCOM), and any number of CORBA
-based systems.
After the inevitable cooling of marketing hype, object libraries continue to be used in both object-oriented programming and distributed information systems. Class libraries are the rough OOP equivalent of older types of code libraries. They contain classes
, which describe characteristics and define actions (methods
) that involve objects. Class libraries are used to create instances, or objects with their characteristics set to specific values. In some OOP languages, like Java
, the distinction is clear, with the classes often contained in library files (like Java's JAR file format
) and the instantiated objects residing only in memory (although potentially able to be made persistent
in separate files). In others, like Smalltalk
, the class libraries are merely the starting point for a system image
that includes the entire state of the environment, classes and all instantiated objects.
(RPC) over a network to another computer. This approach 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 distributed architecture
that makes heavy use of such remote calls, notably client-server systems and application server
s such as Enterprise JavaBean
s.
s that can generate or transform byte code for Java
. They are used by aspect-oriented programming
, some data access frameworks, and for testing to generate dynamic proxy objects. They also are used to intercept field access.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
echo "hello world! ;)" > hello.txt;
gcc -c fmgmt.c;
gcc -g -shared libmyio.c -o libmyio.so;
gcc fmgmt.o -L ./ -lmyio -o fmgmt;
./fmgmt hello.txt;
rm hello.txt;
myio.h
/*
opens stream
@param fpath, omode - path to file, file open mode
@return fp or NULL
FILE *sopen(char *fpath, char *omode);
/*
copy file to file, stream to stream
@param fp, stream
@return 0
int s2s(FILE *fp, FILE *stream);
/*
get info from FILE struct, prints it to stdout
@param FILE *fp
@return 0;
int _sinf_(FILE *fp);
libmyio.c
FILE *sopen(char *fpath, char *omode)
{
FILE *fp;
if(fp = fopen(fpath, omode)){
return fp;
}
else{
return NULL;
}
}
int s2s(FILE *fp, FILE *stream)
{
int c;
while((c = fgetc(fp)) != EOF){
putc(c, stream);
}
return 0;
}
int _sinf_(FILE *fp)
{
printf("_r:%d\n", fp->_r);
printf("_w:%d\n", fp->_w);
printf("_flags:%x\n", fp->_flags);
printf("_file:%x\n", fp->_file);
printf("_lbfsize:%x\n", fp->_lbfsize);
printf("_blksize:%d\n", fp->_blksize);
printf("_offset:%d\n", fp->_offset);
return 0;
}
fmgmt.c
// usage: [./fmgmt hello.txt]
int main(int argc, char **argv, char **environ)
{
FILE *fp;
char *mode = "r";
if(argv[2]){
printf("%s\n", "usage: [./fmgmt hello.txt]");
return 1;
}
else{
if(fp = sopen(argv[1], mode)){
//printf("%s %s\n", argv[1], "opened!");
s2s(fp, stdout);
//_sinf_(fp);
fclose(fp);
}
else{
printf("%s %s\n", argv[1], "failed!");
return 2;
}
}
}
chmod 700 make.sh
./make.sh
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...
, a library is a collection of resources used to develop software. These may include pre-written code
Code reuse
Code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software.-Overview:Ad hoc code reuse has been practiced from the earliest days of programming. Programmers have always reused sections of code, templates, functions, and procedures...
and subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....
s, classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
, values
Value (computer science)
In computer science, a value is an expression which cannot be evaluated any further . The members of a type are the values of that type. For example, the expression "1 + 2" is not a value as it can be reduced to the expression "3"...
or type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...
specifications.
Libraries contain code and data that provide services to independent programs. This encourages the sharing and changing of code and data in a modular
Modular programming
Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
fashion, and eases the distribution of the code and data. Some executable
Executable
In computing, an executable file causes a computer "to perform indicated tasks according to encoded instructions," as opposed to a data file that must be parsed by a program to be meaningful. These instructions are traditionally machine code instructions for a physical CPU...
s are both standalone programs and libraries, but most libraries are not executable. Executables and libraries make references known as links to each other through the process known as linking, which is typically done by a linker.
Most compiled languages have a standard library
Standard library
A standard library for a programming language is the library that is conventionally made available in every implementation of that language. In some cases, the library is described directly in the programming language specification; in other cases, the contents of the standard library are...
although programmers can also create their own custom libraries. Most modern software system
Software system
A software system is a system based on software forming part of a computer system . The term "software system" is often used as a synonym of computer program or software; is related to the application of systems theory approaches in software engineering context and are used to study large and...
s of 2009 provide libraries that implement the majority of system services. Such libraries have commoditized the services which a modern application requires. As such, most code used by modern applications is provided in these system libraries.
The GPL linking exception
GPL linking exception
A GPL linking exception modifies the GNU General Public License to create a new, modified license. Such modified licenses enable software projects which provide library code, to be "linked to" the programs that use them, without applying the full terms of the GPL to the using program...
allows programs which do not license themselves under GPL
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....
to link to libraries licensed under the exception without thereby becoming subject to GPL requirements.
Libraries often contain a jump table of all the methods within it, known as entry points. Calls into the library use this table, looking up the location of the code in memory, then calling it. This introduces overhead in calling into the library, but the delay is so small as to be negligible.
History
The earliest programming concepts analogous to libraries were intended to separate dataData
The term data refers to qualitative or quantitative attributes of a variable or set of variables. Data are typically the results of measurements and can be the basis of graphs, images, or observations of a set of variables. Data are often viewed as the lowest level of abstraction from which...
definitions from the program implementation
Implementation
Implementation is the realization of an application, or execution of a plan, idea, model, design, specification, standard, algorithm, or policy.-Computer Science:...
. JOVIAL
JOVIAL
JOVIAL is a high-order computer programming language similar to ALGOL, but specialized for the development of embedded systems .JOVIAL is an acronym for "Jules Own Version of the International...
brought the "COMPOOL" (Communication Pool) concept to popular attention in 1959, although it adopted the idea from the large-system SAGE
Semi Automatic Ground Environment
The Semi-Automatic Ground Environment was an automated control system for tracking and intercepting enemy bomber aircraft used by NORAD from the late 1950s into the 1980s...
software. Following the computer science principles of separation of concerns
Separation of concerns
In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...
and information hiding
Information hiding
In computer science, information hiding is the principle of segregation of the design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed...
, "Comm Pool's purpose was to permit the sharing of System Data among many programs by providing a centralized data description."
COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
also included "primitive capabilities for a library system" in 1959, but Jean Sammet
Jean E. Sammet
Jean E. Sammet is an American computer scientist who developed the FORMAC programming language in 1962.She received her B.A. in Math from Mount Holyoke College in 1948 and her M.A. in Math from University of Illinois at Urbana-Champaign in 1949...
described them as "inadequate library facilities" in retrospect.
Another major contributor to the modern library concept came in the form of the subprogram innovation of FORTRAN
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...
. FORTRAN subprograms can be compiled independently of each other, but the compiler lacks a linker. So prior to the introduction of modules in Fortran-90, type checking between subprograms was impossible.
Finally, historians of the concept should remember the influential Simula 67. Simula was the first object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
language, and its classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
are nearly identical to the modern concept as used in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, and C#. The class concept of Simula was also a progenitor of the package in Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...
and the module of Modula-2
Modula-2
Modula-2 is a computer programming language designed and developed between 1977 and 1980 by Niklaus Wirth at ETH Zurich as a revision of Pascal to serve as the sole programming language for the operating system and application software for the personal workstation Lilith...
. Even when developed originally in 1965, Simula classes could be included in library files and added at compile time.
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 linker or binder program that searches a set of libraries and other modules in a given order. Usually it is not considered an error if a link target can be found multiple times in a given set of libraries. Linking may be done when an executable file is created, or whenever the program is used at run time.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 memory segment
Memory segment
x86 memory segmentation refers to the implementation of memory segmentation on the x86 architecture. Memory is divided into portions that may be addressed by a single index register without changing a 16-bit segment selector. In real mode or V86 mode, a segment is always 64 kilobytes in size . In...
s of each module referenced.
Some programming languages may use a feature called smart linking wherein 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 loaderLoader (computing)
In computing, a loader is the part of an operating system that is responsible for loading programs. It is one of the essential stages in the process of starting a program, as it places programs into memory and prepares them for execution...
. 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
Position-independent code
In computing, position-independent code or position-independent executable is machine instruction code that executes properly regardless of where in memory it resides...
avoids references to absolute addresses and therefore does not require relocation.
Static libraries
When linking is done 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 compilerCompiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
. 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 static build
Static build
A static build is a compiled version of a program which has been statically linked against libraries.In computer science, linking means taking one or more objects generated by compilers and assemble them into a single executable program...
of the program. A static build may not need any further relocation
Relocation (computer science)
"Relocation is the process of assigning load addresses to various parts of [a] program and adjusting the code and data in the program to reflect the assigned addresses."...
if virtual memory
Virtual memory
In computing, virtual memory is a memory management technique developed for multitasking kernels. This technique virtualizes a computer architecture's various forms of computer data storage , allowing a program to be designed as though there is only one kind of memory, "virtual" memory, which...
is used and no address space layout randomization
Address space layout randomization
Address space layout randomization is a computer security method which involves randomly arranging the positions of key data areas, usually including the base of the executable and position of libraries, heap, and stack, in a process's address space.- Benefits :Address space randomization hinders...
is desired.
Shared libraries
A shared library or shared object is a file that is intended to be shared by executable files and further shared objects files. Modules used by a program are loaded from individual shared objects into memory at load time or run time, rather than being copied by a linker when it creates a single monolithic executable file for the program.Shared libraries can be statically linked, meaning that references to the library modules are resolved and the modules are allocated memory when the executable file is created. But often linking of shared libraries is postponed until they are loaded.
Most modern operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
s can have shared library files of the same format as the executable files. This offers two main advantages: first, it requires making only one loader for both of them, rather than two (having the single loader is considered well worth its added complexity). Secondly, it allows the executables also to be used as shared libraries, if they have a symbol table
Symbol table
In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating to its declaration or appearance in the source, such as its type, scope level and...
. Typical combined executable and shared library formats are ELF
Executable and Linkable Format
In computing, the Executable and Linkable Format is a common standard file format for executables, object code, shared libraries, and core dumps. First published in the System V Application Binary Interface specification, and later in the Tool Interface Standard, it was quickly accepted among...
and Mach-O
Mach-O
Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. A replacement for the a.out format, Mach-O offered more extensibility and faster access to information in the symbol table.Mach-O was once used by...
(both in Unix) and PE
Portable Executable
The Portable Executable format is a file format for executables, object code and DLLs, used in 32-bit and 64-bit versions of Windows operating systems. The term "portable" refers to the format's versatility in numerous environments of operating system software architecture...
(Windows). In Windows, the concept was taken one step further, with even system resources such as fonts being bundled in the PE format. The same is true under OpenStep, where the universal "bundle" format is used for almost all system resources.
Memory sharing
Library code may be shared in memory by multiple processProcess (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...
es as well as on disk. If virtual memory is used, processes execute the same physical page of RAM, mapped into the different address spaces of each process. This has advantages. For instance on the OpenStep
OpenStep
OpenStep was an object-oriented application programming interface specification for an object-oriented operating system that used a non-NeXTSTEP operating system as its core, principally developed by NeXT with Sun Microsystems. OPENSTEP was a specific implementation of the OpenStep API developed...
system, applications were often only a few hundred kilobytes in size and loaded quickly; the majority of their code was located in libraries that had already been loaded for other purposes by the operating system. There is a cost, however; shared code must be specifically written to run in a multitasking environment. In some older environments such as 16-bit Windows or MPE for the HP 3000, only stack based data (local) was allowed, or other significant restrictions were placed on writing a shared library.
Programs can accomplish RAM sharing by using position independent code as in Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
, which leads to a complex but flexible architecture, or by using common virtual addresses as in Windows and OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
. These systems make sure, by various tricks like pre-mapping the address space and reserving slots for each shared library, that code has a great probability of being shared. A third alternative is single-level store
Single-level store
Single-level storage is a term most often associated with the IBM System i operating system, IBM i , although it was originally introduced in 1962 by the Atlas system at Cambridge...
, as used by the IBM System/38 and its successors. This allows position-dependent code but places no significant restrictions on where code can be placed or how it can be shared.
In some cases different versions of shared libraries can cause problems, especially when libraries of different versions have the same file name, and different applications installed on a system each require a specific version. Such a scenario is known as DLL hell
DLL hell
In computing, DLL Hell is a term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions which all run in a single memory space....
, named after the Windows and OS/2 DLL file. Most modern operating systems after 2001, have clean-up methods to eliminate such situations.
Dynamic linking
Dynamic linking or late binding refers to linking performed while a program is being loaded (load time) or executed (run time), rather than when the executable file is created. A dynamically linked library (dynamic-link libraryDynamic-link library
Dynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems...
or DLL under Windows and OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
; dynamic shared object or DSO under Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
systems) is a library intended for dynamic linking. Only a minimum amount of work is done by the linker when the executable file is created; it only records what library routines the program needs and the index names or numbers of the routines in the library. The majority of the work of linking is done at the time the application is loaded (load time) or during execution (run time). The necessary linking program, called a dynamic linker or linking loader, is actually part of the underlying operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
.
Programmers originally developed dynamic linking in the Multics
Multics
Multics was an influential early time-sharing operating system. The project was started in 1964 in Cambridge, Massachusetts...
operating system, starting in 1964, and the MTS (Michigan Terminal System
Michigan Terminal System
The Michigan Terminal System is one of the first time-sharing computer operating systems. Initially developed in 1967 at the University of Michigan for use on IBM S/360-67, S/370 and compatible mainframe computers, it was developed and used by a consortium of eight universities in the United...
), built in the late 1960s.
Optimizations
Since shared libraries on most systems do not change often, systems can compute a likely load address for each shared library on the system before it is needed, and store that information in the libraries and executables. If every shared library that is loaded has undergone this process, then each will load at its predetermined address, which speeds up the process of dynamic linking. This optimization is known as prebindingPrebinding
Prebinding is a method for reducing the time it takes to launch executables in the Mach-O file format. For example, this is what Mac OS X is doing when in the "Optimizing" stage of installing system software or certain applications....
in Mac OS X and prelinking in Linux. Disadvantages of this technique include the time required to precompute these addresses every time the shared libraries change, the inability to use address space layout randomization
Address space layout randomization
Address space layout randomization is a computer security method which involves randomly arranging the positions of key data areas, usually including the base of the executable and position of libraries, heap, and stack, in a process's address space.- Benefits :Address space randomization hinders...
, and the requirement of sufficient virtual address space for use (a problem that will be alleviated by the adoption of 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...
architectures, at least for the time being).
Locating libraries at run time
Loaders for shared libraries vary widely in functionality. Some depend on the executable storing explicit paths to the libraries. Any change to the library naming or layout of the file system will cause these systems to fail. More commonly, only the name of the library (and not the path) is stored in the executable, with the operating system supplying a method to find the library on-disk based on some algorithm.If a shared library that an executable depends on is deleted, moved, or renamed, or if an incompatible version of the library is copied to a place that is earlier in the search, the executable would fail to load. On Windows this is commonly known as DLL hell
DLL hell
In computing, DLL Hell is a term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions which all run in a single memory space....
.
AmigaOS
AmigaOSAmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
stores generic system libraries in a directory defined by the LIBS: path assignment. Application-specific libraries can go in the same directory as the application's executable. AmigaOS will search these locations when an executable attempts to launch a shared library. An application may also supply an explicit path when attempting to launch a library.
Microsoft Windows
Microsoft WindowsMicrosoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
will check the registry
Windows registry
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user...
to determine the proper place to find an ActiveX
ActiveX
ActiveX is a framework for defining reusable software components in a programming language-independent way. Software applications can then be composed from one or more of these components in order to provide their functionality....
DLL, but for other DLLs it will check the directory from where it loaded the program; the current working directory; any directories set by calling the
SetDllDirectory
function; the System32, System, and Windows directories; and finally the directories specified by the PATH environment variableEnvironment variable
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs...
. Applications written for the .NET Framework
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
framework (since 2002), also check the Global Assembly Cache
Global Assembly Cache
The Global Assembly Cache or GAC is a machine-wide .NET assemblies cache for Microsoft's CLR platform. The approach of having a specially controlled central repository addresses the shared library concept and helps to avoid pitfalls of other solutions that led to drawbacks like DLL hell.-...
as the primary store of shared dll files to remove the issue of DLL hell
DLL hell
In computing, DLL Hell is a term for the complications that arise when working with dynamic link libraries used with Microsoft Windows operating systems, particularly legacy 16-bit editions which all run in a single memory space....
.
OpenStep
OpenStepOpenStep
OpenStep was an object-oriented application programming interface specification for an object-oriented operating system that used a non-NeXTSTEP operating system as its core, principally developed by NeXT with Sun Microsystems. OPENSTEP was a specific implementation of the OpenStep API developed...
used a more flexible system, collecting a list of libraries from a number of known locations (similar to the PATH concept) when the system first starts. Moving libraries around causes no problems at all, although users incur a time cost when first starting the system.
Unix-like systems
Most Unix-likeUnix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
systems have a "search path" specifying file system directories
Directory (file systems)
In computing, a folder, directory, catalog, or drawer, is a virtual container originally derived from an earlier Object-oriented programming concept by the same name within a digital file system, in which groups of computer files and other folders can be kept and organized.A typical file system may...
in which to look for dynamic libraries. Some systems specify the default path in a configuration file
Configuration file
In computing, configuration files, or config files configure the initial settings for some computer programs. They are used for user applications, server processes and operating system settings. The files are often written in ASCII and line-oriented, with lines terminated by a newline or carriage...
; others hard-code it into the dynamic loader. Some executable file
Executable
In computing, an executable file causes a computer "to perform indicated tasks according to encoded instructions," as opposed to a data file that must be parsed by a program to be meaningful. These instructions are traditionally machine code instructions for a physical CPU...
formats can specify additional directories in which to search for libraries for a particular program. This can usually be overridden with an environment variable
Environment variable
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs...
, although it is disabled for setuid
Setuid
setuid and setgid are Unix access rights flags that allow users to run an executable with the permissions of the executable's owner or group...
and setgid programs, so that a user can't force such a program to run arbitrary code with root permissions. Developers of libraries are encouraged to place their dynamic libraries in places in the default search path. On the downside, this can make installation of new libraries problematic, and these "known" locations quickly become home to an increasing number of library files, making management more complex.
Dynamic loading
Dynamic loading, a subset of dynamic linking, involves a dynamically linked library loading and unloading at run time on request. Such a request may be made implicitly at compile timeCompile time
In computer science, compile time refers to either the operations performed by a compiler , programming language requirements that must be met by source code for it to be successfully compiled , or properties of the program that can be reasoned about at compile time.The operations performed at...
or explicitly at run time. Implicit requests are made at compile time when a linker adds library references that include file paths or simply file names. Explicit requests are made when applications make direct calls to an operating system's API at run time.
Most operating systems that support dynamically linked libraries also support dynamically loading such libraries via a run-time linker API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
. For instance, Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
uses the API functions LoadLibrary, LoadLibraryEx, FreeLibrary and GetProcAddress with Microsoft Dynamic Link Libraries; POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
based systems, including most UNIX and UNIX-like systems, use dlopen, dlclose and dlsym. Some development systems automate this process.
Object and class libraries
Although originally pioneered in the 1960s, dynamic linking did not reach operating systemOperating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
s used by consumers 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
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
(OOP) was becoming a significant part of the programming landscape. OOP with runtime binding requires additional information that traditional libraries don't supply. In addition to the names and entry points of the code located within, they also require a list of the objects on which they depend. This is a side-effect of one of OOP's main advantages, 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
Compile time
In computer science, compile time refers to either the operations performed by a compiler , programming language requirements that must be met by source code for it to be successfully compiled , or properties of the program that can be reasoned about at compile time.The operations performed at...
, 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
Mainframe computer
Mainframes are powerful computers used primarily by corporate and governmental organizations for critical applications, bulk data processing such as census, industry and consumer statistics, enterprise resource planning, and financial transaction processing.The term originally referred to the...
or minicomputer
Minicomputer
A minicomputer is a class of multi-user computers that lies in the middle range of the computing spectrum, in between the largest multi-user systems and the smallest single-user systems...
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 already handled these tasks, but there was no standard RPC system
Remote procedure call
In computer science, a remote procedure call is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space without the programmer explicitly coding the details for this remote interaction...
.
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 that 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 IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
's System Object Model
System Object Model
In computing, the System Object Model is an object-oriented shared library system developed by IBM. DSOM, a distributed version based on CORBA, allowed objects on different computers to communicate.-Applications:...
(SOM/DSOM), Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
' Distributed Objects Everywhere
Distributed Objects Everywhere
Distributed Objects Everywhere was a long-running Sun Microsystems project to build a distributed computing environment based on the CORBA system in the 'back end' and OpenStep as the user interface. First started in 1990 and announced soon thereafter, it remained vaporware for many years before...
(DOE), NeXT
NeXT
Next, Inc. was an American computer company headquartered in Redwood City, California, that developed and manufactured a series of computer workstations intended for the higher education and business markets...
's Portable Distributed Objects
Portable Distributed Objects
Portable Distributed Objects, or PDO, is a programming API for creating object-oriented code that can be executed remotely on a network of computers. It was created by NeXT Computer, Inc. using their OpenStep system, whose use of Objective-C made the package very easy to write...
(PDO), Digital
Digital Equipment Corporation
Digital Equipment Corporation was a major American company in the computer industry and a leading vendor of computer systems, software and peripherals from the 1960s to the 1990s...
's ObjectBroker
ObjectBroker
ObjectBroker is A distributed object system from DEC based on the CORBA standard....
, Microsoft's Component Object Model
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...
(COM/DCOM), and any number of CORBA
Çorba
Chorba , ciorbă , shurpa , shorpo , or sorpa is one of various kinds of soup or stew found in national cuisines across Middle East...
-based systems.
After the inevitable cooling of marketing hype, object libraries continue to be used in both object-oriented programming and distributed information systems. Class libraries are the rough OOP equivalent of older types of code libraries. They contain classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
, which describe characteristics and define actions (methods
Method (computer science)
In object-oriented programming, a method is a subroutine associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time...
) that involve objects. Class libraries are used to create instances, or objects with their characteristics set to specific values. In some OOP languages, like Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, the distinction is clear, with the classes often contained in library files (like Java's JAR file format
JAR (file format)
In software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata and resources into one file to distribute application software or libraries on the Java platform.JAR files are built on the ZIP file format and have the .jar file extension...
) and the instantiated objects residing only in memory (although potentially able to be made persistent
Persistence (computer science)
Persistence in computer science refers to the characteristic of state that outlives the process that created it. Without this capability, state would only exist in RAM, and would be lost when this RAM loses power, such as a computer shutdown....
in separate files). In others, like Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
, the class libraries are merely the starting point for a system image
System image
A system image in computing is a copy of the entire state of a computer system stored in some non-volatile form such as a file. A system is said to be capable of using system images if it can be shut down and later restored to exactly the same state...
that includes the entire state of the environment, classes and all instantiated objects.
Remote libraries
Another solution to the library issue comes from using completely separate executables (often in some lightweight form) and calling them using a remote procedure callRemote procedure call
In computer science, a remote procedure call is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space without the programmer explicitly coding the details for this remote interaction...
(RPC) over a network to another computer. This approach 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 distributed architecture
Distributed computing
Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...
that makes heavy use of such remote calls, notably client-server systems and application server
Application server
An application server is a software framework that provides an environment in which applications can run, no matter what the applications are or what they do...
s such as Enterprise JavaBean
Enterprise JavaBean
Enterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java APIs in the Java EE specification. EJB is a server-side model that encapsulates the business logic of an application...
s.
Code generation libraries
Code generation libraries are high-level APIApplication programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
s that can generate or transform byte code for Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
. They are used by aspect-oriented programming
Aspect-oriented programming
In computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
, some data access frameworks, and for testing to generate dynamic proxy objects. They also are used to intercept field access.
File naming
- AmigaOSAmigaOSAmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
- The system identifies libraries with a ".library" suffix (for example:
mathieeedoubtrans.library
). These are separate files (shared libraries) that are invoked by the program that is running, and are dynamically-loaded but are not dynamically linked. Once the library has been invoked usually it could not deallocate memory and resources it asked for. Users can force a "flushlibs" option by using AmigaDOSAmigaDOSAmigaDOS is the disk operating system of the AmigaOS, which includes file systems, file and directory manipulation, the command-line interface, and file redirection....
command Avail (that checks free memory in the system and has the option Avail flush that frees memory from libraries left open by programs). Since AmigaOS 4.0 July 2007 First Update, support for shared objects and dynamic linking has been introduced. Now ".so" objects can exist also on Amiga, together with ".library files".- Most modern Unix-likeUnix-likeA Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
systems
- Most modern Unix-like
- The system stores
libfoo.a
andlibfoo.so
files in directories such as/lib
,/usr/lib
or/usr/local/lib
. The filenames always start withlib
, and end with.a
(archive, static library) or.so
(shared object, dynamically linked library). Some systems might have multiple names for the dynamically linked library, with most of the names being names for symbolic links to the remaining name; those names might include the major version of the library, or the full version number; for example, on some systemslibfoo.so.2
would be the filename for the second major interface revision of the dynamically linked librarylibfoo
. The.la
files sometimes found in the library directories are libtoolLibtoolGNU Libtool is a GNU programming tool from the GNU build system used for creating portable compiled libraries. To quote the introduction in the :Libtool is typically used with Autoconf and Automake, two other tools of the GNU build system....
archives, not usable by the system as such.- Mac OS XMac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
- Mac OS X
- The system inherits static library conventions from BSD, with the library stored in a
.a
file, and can use.so
-style dynamically-linked libraries (with the.dylib
suffix instead). Most libraries in Mac OS X, however, consist of "frameworks", placed inside special directories called "bundlesBundle (NEXTSTEP)In NEXTSTEP, OPENSTEP, their lineal descendants Mac OS X, iOS, and in GNUstep, a bundle is a directory that allows related resources such as an application's executable and its graphics to be grouped together, appearing as a single file to the user....
" which wrap the library's required files and metadata. For example, a framework calledMyFramework
would be implemented in a bundle calledMyFramework.framework
, withMyFramework.framework/MyFramework
being either the dynamically linked library file or being a symlink to the dynamically linked library file inMyFramework.framework/Versions/Current/MyFramework
.- Microsoft WindowsMicrosoft WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
- Microsoft Windows
- Dynamically linkable librariesDynamic-link libraryDynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems...
usually have the suffix*.DLL
, although other file name extensions may be used for specific purpose dynamically-linked libraries, e.g.*.OCX
for OLEObject Linking and EmbeddingObject Linking and Embedding is a technology developed by Microsoft that allows embedding and linking to documents and other objects. For developers, it brought OLE Control eXtension , a way to develop and use custom user interface elements...
libraries. The interface revisions are either encoded in the file names, or abstracted away using COM-objectComponent Object ModelComponent Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...
interfaces. Depending on how they are compiled,*.LIB
files can be either static libraries or representations of dynamically linkable libraries needed only during compilation, known as "Import Libraries". Unlike in the UNIXUnixUnix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
world, where different file extensions are used, when linking against.LIB
file in WindowsMicrosoft WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
one must first know if it is a regular static library or an import library. In the latter case, a.DLL
file must be present at run time.
dso
make.sh- !/bin/sh
- openbsd 4.9
- gcc 4.2.1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
echo "hello world! ;)" > hello.txt;
gcc -c fmgmt.c;
gcc -g -shared libmyio.c -o libmyio.so;
gcc fmgmt.o -L ./ -lmyio -o fmgmt;
./fmgmt hello.txt;
rm hello.txt;
myio.h
- include
/*
opens stream
@param fpath, omode - path to file, file open mode
@return fp or NULL
FILE *sopen(char *fpath, char *omode);
/*
copy file to file, stream to stream
@param fp, stream
@return 0
int s2s(FILE *fp, FILE *stream);
/*
get info from FILE struct, prints it to stdout
@param FILE *fp
@return 0;
int _sinf_(FILE *fp);
libmyio.c
- include "myio.h"
FILE *sopen(char *fpath, char *omode)
{
FILE *fp;
if(fp = fopen(fpath, omode)){
return fp;
}
else{
return NULL;
}
}
int s2s(FILE *fp, FILE *stream)
{
int c;
while((c = fgetc(fp)) != EOF){
putc(c, stream);
}
return 0;
}
int _sinf_(FILE *fp)
{
printf("_r:%d\n", fp->_r);
printf("_w:%d\n", fp->_w);
printf("_flags:%x\n", fp->_flags);
printf("_file:%x\n", fp->_file);
printf("_lbfsize:%x\n", fp->_lbfsize);
printf("_blksize:%d\n", fp->_blksize);
printf("_offset:%d\n", fp->_offset);
return 0;
}
fmgmt.c
- include "myio.h"
// usage: [./fmgmt hello.txt]
int main(int argc, char **argv, char **environ)
{
FILE *fp;
char *mode = "r";
if(argv[2]){
printf("%s\n", "usage: [./fmgmt hello.txt]");
return 1;
}
else{
if(fp = sopen(argv[1], mode)){
//printf("%s %s\n", argv[1], "opened!");
s2s(fp, stdout);
//_sinf_(fp);
fclose(fp);
}
else{
printf("%s %s\n", argv[1], "failed!");
return 2;
}
}
}
chmod 700 make.sh
./make.sh
See also
- Code reuseCode reuseCode reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software.-Overview:Ad hoc code reuse has been practiced from the earliest days of programming. Programmers have always reused sections of code, templates, functions, and procedures...
- Linker (computing)
- Loader (computing)Loader (computing)In computing, a loader is the part of an operating system that is responsible for loading programs. It is one of the essential stages in the process of starting a program, as it places programs into memory and prepares them for execution...
- Dynamic-link libraryDynamic-link libraryDynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems...
- Object fileObject fileAn object file is a file containing relocatable format machine code that is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as input to the linker....
- Plug-in
- PrebindingPrebindingPrebinding is a method for reducing the time it takes to launch executables in the Mach-O file format. For example, this is what Mac OS X is doing when in the "Optimizing" stage of installing system software or certain applications....
- Static libraryStatic libraryIn 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...
- Runtime libraryRuntime libraryIn computer programming, a runtime library is a special program library used by a compiler, to implement functions built into a programming language, during the execution of a computer program...
- Visual Component LibraryVisual Component LibraryVCL is a visual component-based object-oriented framework for developing Microsoft Windows applications. It was developed by Borland for use in, and tightly integrated with, its Delphi and C++Builder RAD tools...
(VCL) - Component Library for Cross PlatformComponent Library for Cross PlatformComponent Library for Cross Platform , is a cross-platform visual component-based framework for developing Microsoft Windows and Linux applications. It is developed by Borland for use in its Kylix, Delphi, and C++ Builder software development environment....
(CLX) - Lazarus Component Library (LCL)
- C standard libraryC standard libraryThe C Standard Library is the standard library for the programming language C, as specified in the ANSI C standard.. It was developed at the same time as the C POSIX library, which is basically a superset of it...
- Java Class LibraryJava Class LibraryThe Java Class Library is a set of dynamically loadable libraries that Java applications can call at run time. Because the Java Platform is not dependent on any specific operating system, applications cannot rely on any of the existing libraries...
- Base Class LibraryBase Class LibraryThe Base Class Library is a standard library available to all languages using the .NET Framework. .NET includes the BCL in order to encapsulate a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation, which makes...
- Generic programmingGeneric programmingIn a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...
(used by the C++ standard libraryC++ standard libraryIn C++, the C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself...
) - sonameSonameIn Unix operating systems, a soname is a field of data in a shared object file. The soname is a string, which is used as a "logical name" describing the functionality of the object...
External links
- Program Library HOWTO for Linux
- Shared Libraries - 'Linkers and Loaders' by John R. Levine
- Dynamic Linking and Loading - 'Linkers and Loaders' by John R. Levine
- 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
- LIB BFD - the Binary File Descriptor Library
- 1st Library-Centric Software Design Workshop LCSD'05 at OOPSLA'05
- 2nd Library-Centric Software Design Workshop LCSD'06 at OOPSLA'06
- How to create shared library(with much background info)
- Anatomy of Linux dynamic libraries
- Criticisms of dynamic linking.
- Reusable Software Assets