Static libraries in C.

Angui Clavijo Gutiérrez
2 min readMar 8, 2021

What is a library, this a file containing several object files, can be used as a single entity in a linking phase of a program; the library is indexed so it is for find symbols how functions, variables and so on. Linking program whose object files are ordered in libraries is faster than linking program whose object files are separate on the disk, we have fewer files to look for and open, which even further speeds up linking.

The static libraries aren’t loaded by the compiler at run-time; only the executable file need be loaded, this contrast having the compiler pull in multiple object files during linking.

How to create them:

The static libraries are created using type of archiving such ar that take one o more files objects (file.o) and generate an archive file whit extension .a (file.a) this is a static library.

$ gcc -c sum.c // produces a sum.o object file

The archives object file, we can archive them and make a static library using ar.

$ ar -rc libforme.a sum.o

The command above will create a static library called “libforme.a” some files archivers automatically organize and index the library, otherwise we can used a command ranlib to generate and store an index in the archive.

the index list symbols defined by a member of an archive that is a relocatable object file and called nm

$ nm libforme.a

// sample output

sum.o:000000000000002e T sum

Now, we are use our library.