How to link to a static library in C? How to link to a static library in C? c c

How to link to a static library in C?


cc -o yourprog yourprog.c -lstatic

or

cc -o yourprog yourprog.c libstatic.a


You should #include "libstatic.h", i.e. use the appropriate header file in your code (that's why your code doesn't compile) and include the path to your libstatic.a in the linker options as one of your input libraries.

This webpage has some examples on linking to a static library, e.g.

gcc -I. -o jvct jvct.c libjvc.a


I had to set the library path in my makefile. For this case you could use:

gcc -o myapp main.c -L. -lstatic