Makefile循环依赖 [英] Makefile circular dependency

查看:181
本文介绍了Makefile循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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.cN.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆