A C libraries tl;dr
Why use a library?
Simply put, every time your program calls upon a function, that function code is compiled with your executable every time that function is called, but if you were to use a library, the compiler would only need to call on that library once near the end of compilation. Now these functions would be available each time a function needs to be called.
How do they work?
Libraries are comprised of the object code of several functions. You can create an archive of multiple .o files by using the ar
command. They are accessed during the linking phase of the compilation process. They index all functions, symbols and variables rather than compiling all individual functions .
How to make a library?
Organize all the functions you wish to add into a directory.
Compile them into .o files using gcc -c .
Create a library with the archive function and add your library namear -rc [libname.a] [.o file(s)]
Now you have a library! You can run the ranlib
function on your library to index it or check if it was case it was not.