简体   繁体   中英

How to link to a static library in C?

I use code::blocks to compile my static library. The output result is a libstatic.a file. Now, how do I link to my library to use functions that were compiled?

(I tried to use #include "libstatic.a" but my project doesn't compile)

cc -o yourprog yourprog.c -lstatic

要么

cc -o yourprog yourprog.c libstatic.a

You should #include "libstatic.h" , ie 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, eg

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
gcc -I. -o jvct jvct.c libjvc.a

要纯粹静态链接,请使用-static

cc -static yourprogram.c libstatic.a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM