Welcome





Thursday, April 7, 2011

CREATION OF STATIC LIBRARIES IN LINUX

An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive). A static library is an archive whose members are object files. A library makes it possible for a program to use common routines without the administrative overhead of maintaining their source code, or the processing overhead of compiling them each time the program is compiled. Conventionally, static libraries end with the ``.a'' suffix. Dynamic linking involves loading the subroutines of a library into an application program at load time or runtime, rather than linking them in at compile time. With static linking, it is enough to include those parts of the library that are directly and indirectly referenced by the target executable (or target library).
Implementation:
The XXX.c file containing the code for library is converted into object file. Then, the archiver (ar) is invoked to produce a static library (named libXXXX.a) out of the object file XXX.o. It is important to note that the library must start with the three letters lib and have the suffix .a since it is static however shared libraries have .so as suffix.When a program needs a function, that is stored in a static library,it includes the header file that declares the function.The program that uses the library should be linked with it and linking is done using the gcc commands(-lname).The user program is then executed to obtain the output.The striking feature of static linking is that it avoids dependency problems and increases reusability.