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中的
发布评论