Do you know anything about static libraries in C ?
Santiago Neira
Software Developer | Estudiante Analista en Tecnologías de la Información | Javascript | ReactJS | NextJS | NodeJS | SQL | AWS
In this opportunity we have as a main topic the static libraries in C
we are going to talk about topics such as:
> First, what are the libraries in programming?
In programming, a library is?a collection of precompiled routines that a program can use. The routines, sometimes called modules, are stored in object format( file.o). Libraries are particularly useful for storing frequently used routines because you do not need to explicitly link them to every program that uses them.
Well, now let's get into our main topic :
In C a, a static library is a compiled object file containing all things required by the main program to operate.
These are loaded near the end of the build during its linking phase.
1 => Why should we use them?
Without having much detail about what you are doing behind the scenes, there is a very big runtime advantage, because we are putting together all the symbols that the program is going to need for work.
2 => How they work and How to create them?
About how the library works internally we already talked about above but it can be seen implicitly during these cases
Steps to create a static library:
1- put all relevant files for your program in one directory next to main.h with all required prototypes.
2- Compile all ".c" files with the -c option to create a object file for each .c file
with a command like this => gcc -c *.c
领英推荐
3- with the following command => ar -rc library_name.c *.o to archive all .o files into a static library .a file
3 => How can we use them?
Then of followed this steps
Instead of having to include all relevant file names in the compilation command, only the library (.a) file need be referenced
with a command like this => gcc main.c library_name.a
As a conclusion or closing we can say that using a static library in our programs can be very helpful, reducing the programs size taking up less space on the disk.
This article was very useful to me for write this :
If you got here I hope this article has been of interest to you and thank you very much for reading me :)
STEM MBA Candidate at The George Washington University | Finance-Risk Management | System-Operations | Business | Taxes
3 年Very interesting, thank you!