makefile 中的

编程入门 行业动态 更新时间:2024-10-28 08:22:55
本文介绍了makefile 中的 -I 和 -L 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

makefile 中 -I 和 -L 标志的用途是什么?

What is the usage of the -I and -L flags in a makefile?

推荐答案

这些通常是链接器命令行的一部分,或者直接在目标操作中提供,或者更常见地分配给 make 将被扩展以形成链接命令的变量.在这种情况下:

These are typically part of the linker command line, and are either supplied directly in a target action, or more commonly assigned to a make variable that will be expanded to form link command. In that case:

-L 是包含库的目录的路径.库的搜索路径.

-L is the path to the directories containing the libraries. A search path for libraries.

-l 是您要链接的库的名称.

-l is the name of the library you want to link to.

例如,如果您想链接到库 ~/libs/libabc.a,您需要添加:

For instance, if you want to link to the library ~/libs/libabc.a you'd add:

-L$(HOME)/libs -labc

要利用默认的隐式链接规则,请将这些标志添加到变量 LDFLAGS,如

To take advantage of the default implicit rule for linking, add these flags to the variable LDFLAGS, as in

LDFLAGS+=-L$(HOME)/libs -labc

把LDFLAGS和LIBS分开是个好习惯,例如

It's a good habit to separate LDFLAGS and LIBS, for example

# LDFLAGS contains flags passed to the compiler for use during linking LDFLAGS = -Wl,--hash-style=both # LIBS contains libraries to link with LIBS = -L$(HOME)/libs -labc program: a.o b.o c.o $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ # or if you really want to call ld directly, # $(LD) $(LDFLAGS:-Wl,%=%) $^ $(LIBS) -o $@

即使它可能以其他方式工作,-l... 指令也应该在引用这些符号的对象之后.如果链接以错误的顺序完成,一些优化(-Wl,--as-needed 是最明显的)将失败.

Even if it may work otherwise, the -l... directives are supposed to go after the objects that reference those symbols. Some optimizations (-Wl,--as-needed is the most obvious) will fail if linking is done in the wrong order.

更多推荐

makefile 中的

本文发布于:2023-07-29 09:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239335.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!