Static Libraries

written by: Lorent Konenbal; article published: year 2007, month 07;


In: Root » Computers and technology » Linux » Static Libraries

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

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.

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article