Static libraries in c
This time I will inform you about the static libraries in c and how they work
Whats are libreries?
Libraries are a group of files that have functionalities defined by third parties, and that can be used by any executable. Libraries contain variables and functions inside, certain types of files that we can import or include in our program are known as libraries (or libraries). These files contain the specifications of different functionalities already built and usable, such as reading from the keyboard or displaying something on the screen, among many others.
Whats are static libraries?
It is a library that is "copied" into our program when we compile it. Once we have the executable of our program, we could delete it and our program would continue to work, since it has a copy of everything it needs. Only that part of the library that is needed is copied. For example, if the library has two functions and our program calls only one, only that function is copied.
What are the advantages and disadvantages of each of these types of bookstores?
How to create a static libraries?
1)
We use this so that the header file is only defined once instead of every time it's called, if you don't use it you might have some problems when compiling.
领英推荐
2) The next step is to create the .o files, we will do this using the gcc compiler with the -c parameter and the *.c wildcard.
3) To create the library file, which is actually an archive file, we'll use ar.
We are using the -c (create) option to create the library file, the -r (add with replace) option to add them to the library file, and the *.o wildcard to add all the files we have to them.
4) Time to use our new library
At compile time we won't need to include all the relevant filenames in the build command, we just need to reference the library file mylib.a