How to link to a static library in C?

前端 未结 5 774
旧巷少年郎
旧巷少年郎 2020-12-01 03:54

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

相关标签:
5条回答
  • 2020-12-01 04:05
    gcc -I. -o jvct jvct.c libjvc.a
    
    0 讨论(0)
  • 2020-12-01 04:08

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

    gcc -o myapp main.c -L. -lstatic
    
    0 讨论(0)
  • 2020-12-01 04:19
    cc -o yourprog yourprog.c -lstatic
    

    or

    cc -o yourprog yourprog.c libstatic.a
    
    0 讨论(0)
  • 2020-12-01 04:19

    To link purely statically, use -static

    cc -static yourprogram.c libstatic.a
    
    0 讨论(0)
  • 2020-12-01 04:25

    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
    
    0 讨论(0)
提交回复
热议问题