在 GCC 中链接包含文件
我永远不记得在 GCC 中链接包含文件时要输入什么内容,事实上我唯一记得的是 math.h
的 -lm
。我现在特别关心的是sys/time.h
。
此页面澄清了一些事情,但我仍然想要一个列表。
有谁知道链接选项的良好列表?
编辑:
也许我的问题不清楚。我想知道我需要在命令行中输入什么内容(例如用于数学的 -lm
或用于 pthread 的 -lpthread
),以便在制作时可能需要链接的各种库C 程序。
I can never remember what to type when linking include files in GCC, in fact the only one I can remember is -lm
for math.h
. The one I am specifically concerned with right now is sys/time.h
.
This page clears things up some, but I would still like a list.
Does anyone know of a good list of linking options?
EDIT:
Maybe my question was not clear. I want to know what I need to type at the command line (like -lm
for math or -lpthread
for pthread) for the various libraries I might need to link when making C programs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
中提供的功能在libc.so
(C 库)中实现。您不需要链接任何其他内容,因为 gcc 本身应该自动链接到libc.so
。没有“包含文件的链接”,而是链接到包含代码定义的符号的库。-l
标志是 GCC 的链接器选项 用于指定要链接的其他库。编辑,因为我的 gcc 在编译时对我的源代码执行优化
此外,该链接中的信息有点过时 - 您不需要指向libm (这就是
-l m
或-lm
的作用)。The functionality provided in
<sys/time.h>
is implemented inlibc.so
(C library). You don't need to link anything else in as gcc should automatically link tolibc.so
by itself. There is no 'linking of include files', rather you are linking against libraries that contain the symbols defined by code.The
-l
flag is one of GCC's linker options and is used to specify additional libraries to link against.edit because my gcc was performing optimizations on my source code at compile time
Also, the information in that link is a little outdated - you should not need an explicit link tolibm
(which is what-l m
or-lm
does) in modern GCC.我不确定我是否理解你的问题,但 -lm 不是 ld 选项, -l 是一个选项, -lx 链接 libx.a (或 .so,这取决于)。您可能需要查看 ld 手册以获取完整的选项列表。
我认为除 math 之外的所有其他标准库都包含在 libc.so(.a) (-lc) 中
I'm not sure i understand your question but -lm is not an ld option, -l is an option and -lx links libx.a (or .so, it depends). you might want to look at the ld manual for a full list of options.
I think all other standard libraries other than math are included in libc.so(.a) (-lc)