Section 8.1. Static Libraries

   


8.1. Static Libraries

Static libraries are simply collections of object files arranged by the ar (archiver) utility. ar collects object files into one archive file and adds a table that tells which object files in the archive define what symbols. The linker, ld, then binds references to a symbol in one object file to the definition of that symbol in an object file in the archive. Static libraries use the suffix .a.

You can convert a group of object files into a static library with a command like

 ar rcs libname.a foo.o bar.o baz.o 


You can also add one object file at a time to an existing archive.

 ar rcs libname.a foo.o ar rcs libname.a bar.o ar rcs libname.a baz.o 


In either case, libname.a will be the same. The options used here are:

r

Includes the object files in the library, replacing any object files already in the archive that have the same names.

c

Silently create the library if it does not already exist.

s

Maintain the table mapping symbol names to object file names.


There is rarely any need to use other options when building static libraries. However, ar has other options and other capabilities; the ar man page describes them in detail.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net