如何链接到C 中的静态库?
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
或者
or
您应该
#include "libstatic.h"
,即在代码中使用适当的头文件(这就是您的代码无法编译的原因)并包含 < code>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 yourlibstatic.a
in the linker options as one of your input libraries.This webpage has some examples on linking to a static library, e.g.
我必须在我的 makefile 中设置库路径。对于这种情况,您可以使用:
I had to set the library path in my makefile. For this case you could use:
要纯静态链接,请使用
-static
To link purely statically, use
-static