How do I create and use my own static library in C?


I want to my make own library and have it use the same syntax as the standard C libraries as in


So that it looks like #include and some of the libraries that are included with C.

Can I make the library static as opposed to linking so that I can compile it in GCC without additional arguments, as if I were using another library like stdio.h or string.h?

This seems simple enough.

  • Develop the library (create as many source files as you need).

  • Build the source files into a shared library (.so) using a tool like CMAKE (which i strongly recommend).

  • Copy that library to your library path (i.e. /usr/lib)

  • Later on, all you have to do is import your lib: (i) in the source using #include<mylib.h>; (ii) when building (also using CMAKE) or using the flag (-lmylib) in the GCC compiler: gcc -lmylib myfiles.c -o myoutput.