Static libraries are collection of ordinary object files. For a static library, the actual code is extracted from the library by the linker and used to build the final executable at the point you compile/build your application.
1.Creates .c file, that contains functions in your library and application.
2.Create object file.eg
gcc -c add.c -o add.o
//-c means to create an intermediary object file, rather than an executable.
3.Create static library.This step is to bundle multiple object files in one static library.
ar rcs libststlib.a add.o sub.o
//r means to insert with replacement, c means to create a new archive,
and s means to write an index.
NOTE: A static library must start with ‘lib’ and have the suffix ‘.a’.
4.Making Executable and linking with library.
gcc -o operation operation.o -L. -lststlib
Note: -L. is used to tell that the static library is in current folder or you can provide the path too.
-l searches for the library named library at the time of linking. Linker searches and processes libraries and object files in the order they are specified.
5. Run the program.