C static libraries

Victor Zuluaga
2 min readMar 2, 2020


Together with the compiler of C programming lenguage, are included some files it called library. these files contain source code object of a lot programs it allow to do things common. as to read the keyboard, to write in the screen, handle numbers, to perform functions mathmatic.

Why use libraries: It’s important to use libraries because they help us a to perform the tasks more simple and with minus code. it’s say, we can call the function with some library without needed of go back to write the function, Libraries are classified by the type of work they do, there are input and output libraries, math, memory management, text management, only you call the function writting #include <namelibrary.h> in the header of your file.

someones standard libraries of C lenguage are:
Stdio.h — main
and other many more.

Libraries are not only external files created by others, it is also possible to create our own libraries and use them in our programs.

how to create them: to create a library in C first we must have all files .c with the function that we want to include within of the library.

for example:

once we have all files we must compiler it.
gcc -Wall -pedantic -Werror -Wextra -c *.c

with this command above we say. To compile all files .c in code assamble.
if you need more details to see: what happen when you type gcc main.c all credit to the writter.

then of the code above we have all files .o

then, now we can create our library executing the next code:
ar -rc libname.a *.o

ar — This command creates a static library named libname.a with code object .o
name the library can to be you want but always must go between lib_____a
The 'c' flag tells ar to create the library if it doesn't already exist. The 'r' flag tells it to replace older object files in the library, with the new object files.

After a library is created is need to index it with the code:
ranlib libholbertonschool.a

and ready, you can use how you want.