如何链接到C 中的静态库?

发布于 2025-01-12 07:48:19 字数 125 浏览 5 评论 0原文

我使用 code::blocks 来编译我的静态库。输出结果是一个libstatic.a文件。 现在,如何链接到我的库以使用已编译的函数?

(我尝试使用#include“libstatic.a”,但我的项目无法编译)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

╭⌒浅淡时光〆 2025-01-19 07:48:19
cc -o yourprog yourprog.c -lstatic

或者

cc -o yourprog yourprog.c libstatic.a
cc -o yourprog yourprog.c -lstatic

or

cc -o yourprog yourprog.c libstatic.a
瞳孔里扚悲伤 2025-01-19 07:48:19

您应该#include "libstatic.h",即在代码中使用适当的头文件(这就是您的代码无法编译的原因)并包含 < code>libstatic.a 在链接器选项中作为输入库之一。

这个网页有一些链接到静态库的示例,例如

gcc -I. -o jvct jvct.c libjvc.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
百善笑为先 2025-01-19 07:48:19

我必须在我的 makefile 中设置库路径。对于这种情况,您可以使用:

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

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

gcc -o myapp main.c -L. -lstatic
香草可樂 2025-01-19 07:48:19

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

cc -static yourprogram.c libstatic.a

To link purely statically, use -static

cc -static yourprogram.c libstatic.a
眼眸里的快感 2025-01-19 07:48:19
gcc -I. -o jvct jvct.c libjvc.a
gcc -I. -o jvct jvct.c libjvc.a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文