C static libraries
¿ Why use libraries ?
The libraries is awesome when you want use a function that you use many times and this function never change in this cases the libraries is the best option , also the some advavantages have the libraries are the speed, Lower cost in development, etc…
¿ How work the libraries ?
A librery is a file that contains a set of functions executables , this libraries are available to be used for other programs that use
¿ How to create a library ?
To create a library in C then you have the functions executables you can create a librarie with the command ar the name of the library shoul star with libName and extention is .a, the following example create a library with 3 function:
- ar -rc libprueba.a *o -> (-c) is the flag to create a library (-r) is to replace the files have *o (.a) the extention.
- ar -t libprueba.a -> (-t)Display a table listing the contents of library.
¿ How to use a library ?
- gcc test.c -L. -ltest -o test -> Compile test.c (-L) looks in the directory for library files (-l)omit lib and the extention .a (-o) to give the name of the executable
- ./test -> run the executable