简体   繁体   English

Makefile:循环 - 依赖项已删除

[英]Makefile: Circular - Dependency dropped

I have designed a Makefile that compiles all the .c files individually and produces a .o respectively (I think this happens Implicitly and works perfectly fine).我设计了一个 Makefile,它单独编译所有 .c 文件并分别生成一个 .o (我认为这是隐式发生的,并且工作得很好)。

The executable (.out) is not being generated from the .o files.可执行文件 (.out) 不是从 .o 文件生成的。

Makefile:生成文件:

TARGET = all.out
OBJS = file1.o file2.o file3.o
CC = gcc
CFLAGS = -g -Wall
all : $(TARGET)
$(TARGET) : $(OBJS)
#   gcc $^ -o $@
run : $(TARGET)
    ./$<
clean :
    rm -rf *.o $(TARGET)

Output:输出:

$ make 
make: Circular all.out <- all dependency dropped.
gcc -g -Wall    -c -o file1.o file1.c
gcc -g -Wall    -c -o file2.o file2.c
gcc -g -Wall    -c -o file3.o file3.c
cp file1.o a.out

Note: The Makefile works perfectly and produces the perfect results if the line no.注意: Makefile 可以完美运行并产生完美的结果,如果该行没有。 7 present in it is uncommented.其中有 7 个未注释。

line no.行号7: 7:

#   gcc $^ -o $@

Output when line no.行号时输出。 7 is uncommented (Works perfectly as intended): 7 未注释(按预期完美工作):

gcc -g -Wall    -c -o file1.o file1.c
gcc -g -Wall    -c -o file2.o file2.c
gcc -g -Wall    -c -o file3.o file3.c
gcc file1.o file2.o file3.o -o a.out

I am new to Makefiles.我是 Makefile 的新手。

Queries:查询:

  1. why does commenting line no.为什么评论行号。 7 causing this issue and uncommenting it works perfectly? 7 导致此问题并取消注释它可以正常工作吗?
  2. What is cp in the first output when line no.7 was commented?当第 7 行被注释时,第一个输出中的cp是什么?
  3. What does circular - dependency dropped error occur?循环依赖丢弃错误会发生什么?

I can't explain how you are seeing the problem you showed to us.我无法解释您如何看待您向我们展示的问题。 Either what you wrote above is not actually what you're using, or you have a buggy version of GNU make.要么你上面写的不是你实际使用的,要么你有一个错误的 GNU make 版本。 I can't reproduce the behavior you're seeing.我无法重现您所看到的行为。

But, I'm sure it's related to this: GNU make has a built-in rule that knows how to build an xx.out file from a file xx for any xx :但是,我确信它与此有关:GNU make 有一个内置规则,它知道如何从文件xx为任何xx构建xx.out文件:

# make -p -f/dev/null
  ...
%.out: %
#  recipe to execute (built-in):
        @rm -f $@
        cp $< $@

If you comment out your own recipe as an explicit rule, then make will search for one among the pattern rules it knows about and it will find this built-in pattern rule.如果您将自己的配方注释为显式规则,则 make 将在它知道的模式规则中搜索一个,并找到这个内置的模式规则。

However this rule shouldn't match based on what you've shown us: in order for it to match with a target of a.out , make would have to find or know how to build a target a and that doesn't seem to be available.但是,根据您向我们展示的内容,此规则不应匹配:为了使其与a.out的目标匹配,make 必须找到或知道如何构建目标a而这似乎并不能得到的。 Also, knowing how to build a would show a circular dependency on a.out .此外,知道如何构建a将显示对a.out的循环依赖。

If your makefile was:如果您的 makefile 是:

TARGET = all.out

THEN it would all make perfect sense because you would have:那么这一切都会很有意义,因为您将拥有:

all : all.out
all.out : file1.o file2.o file3.o

and after the implicit rule match %.out: % it would expand like this:在隐式规则匹配%.out: %之后,它会像这样扩展:

all : all.out
all.out : all file1.o file2.o file3.o
        @rm -f all.out
        cp all all.out

So I assume that when you copied the output into your question you changed it: best to not do that.所以我假设当你将输出复制到你的问题中时,你改变了它:最好不要这样做。 You should post exactly the problem you have (and verify you still have the problem with what you posted).您应该准确地发布您遇到的问题(并验证您发布的内容仍然存在问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM