Makefile循环依赖 [英] Makefile circular dependency
问题描述
这是我的Makefile:
Here is my Makefile:
.PHONY: all homework1
CFLAGS= -g -O0 -Wall -Werror -Wno-unused-function
LDFLAGS= -lm
all : homework1
homework1 : program.tab.o program.lex.o
%.o : %.c
gcc -o$@ -c $(CFLAGS) $<
%.lex.c : %.lex %.tab.h
flex -o$@ $<
%.tab.c %.tab.h : %.y
bison --verbose -o$@ -d $<
每当我尝试编译时,都会收到警告make: Circular program.lex <- program.lex.o dependency dropped.
,我根本看不到makefile中program.lex
如何依赖于program.lex.o
.我看到依赖树的深度大约是4层,但是看起来不是圆形的.
Whenever I try to compile, I get the warning make: Circular program.lex <- program.lex.o dependency dropped.
I don't see how program.lex
is dependent on program.lex.o
at all in the makefile. I see how the dependency tree is about 4 layers deep, but it doesn't look circular.
如何改善我的Makefile?
How can I improve my makefile?
推荐答案
@aaa鲤鱼是正确的,它是一个隐含规则,但它不是LEX
规则之一,因为它们是从N.c
或N.r
N.l
,这是从N.o
构建N
的规则.在我看来,这就像info (make) Catalogue of Rules
中所述的链接单个目标文件"规则.将.lex
文件重命名为.l
文件将解决此问题.
@aaa carp is correct that is an implicit rule, but it's not one of the LEX
rules, because they build N.c
or N.r
from N.l
, and this is a rule that's building N
from N.o
. That looks to me like the "Linking a single object file" rule, described in info (make) Catalogue of Rules
. Renaming your .lex
files to .l
files will fix this problem.
另外:运行flex
,我认为您真的不需要.tab.h
文件来构建词法分析器源.尝试以下方法:
Also: running flex
, I don't think you really need the .tab.h
file to build the lexer source. Try this instead:
%.l.c: %.l
flex -o$@ $<
program.l.o: program.tab.h
这会将额外的依赖项添加到program.l.o
.
This will add the extra dependency to program.l.o
.
这篇关于Makefile循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!