C - static libraries
Marcos Pimienta
Software Engineer | DevOps | Cloud Engineer #JavaScript #Kubernetes #Docker #Python #GCP #AWS #NodeJS
Why use libraries in C?
To make your life simple as a developer, if you do not want to spend a lot of time writing code, you can use libraries to simplify this process and make it easier for you to concentrate on logic problems rather than "referencing" standard functions.
All libraries are collections of functions that get referenced by the linker on the compilation process, at this point in the object code that you have in the process you will find there undefined references, which the linker will look up in the runtime library so it can be linked or defined.
How to make a libary you wonder? better run!!! just kidding, to make a static library you will to do a small compilation process before, you will need to create object code from the functions files that end up with ".c" to put inside the static library, for that you type the following command: gcc -c *.c this command will generate object code for every .c element taht you have on the current folder, once you got the object code for each of those files, run the following command: ar -rc liball.a *.o this command will make all the object files into a static library called "liball.a".
How to use them? Its simple, whenever you need to compile a program, define your specifics needs, if you might need a static which will belong specifically to the application that you are building, or if it is a shared library that can be used by multiple programs or application during the compilation process? let it be one or the other, we know that during compilation process, the libraries cited on the programs will be expanded and transformed into object code later on.