问题描述
我有这个Makefile:
I have this Makefile:
all: src/exec
src/exec:
make -C src/
src/exec: src/bar.o
src/bar.o: src/bar.h
在src
目录中的这些文件:
touch src/exec src/bar.o src/bar.h
当我点击make时,我得到:
When I hit make I get:
$ make
make: Nothing to be done for 'all'.
现在,如果我对src/bar.h
进行了更改,则会得到相同的结果:
Now, if I make a change to src/bar.h
, I get the same:
$ touch src/bar.h
$ make
make: Nothing to be done for 'all'.
我不明白. Make应该遵循依赖关系链:
I don't understand it. Make should follow the dependencies chain:
all <- src/exec <- src/bar.o <- src/bar.h
src/bar.h
是否将目标更改为要重建的目标?
If src/bar.h
changes the target as to be rebuilt right?
当我使用由gcc -MM
或makedepend
生成的*.d
文件时,我注意到这些文件中的规则完全相同:
When I am using *.d
files generated by either gcc -MM
or makedepend
, I notice exactly the same rules in these files:
bar.o: bar.c bar.h
exec: bar.o foo.o
所以我想做的事情应该在某个时候起作用.我错了吗?
So what I am trying to do should work at some point. Am I wrong?
推荐答案
由于您已明确要求提供正在发生的情况的解释,而不是对您要解决的问题提供任何帮助,因此,我将提供前者而忽略后者.
Since you've asked explicitly for an explanation of what is happening, rather than any help with the problem you're trying to solve, I'll provide the former and ignore the latter.
如果使用make -d
并检查输出,您将快速看到会发生什么;这是摘录:
If you use make -d
and examine the output you'll quickly see what happens; here's an excerpt:
Finished prerequisites of target file 'src/bar.o'.
Prerequisite 'src/bar.h' is newer than target 'src/bar.o'.
No recipe for 'src/bar.o' and no prerequisites actually changed.
No need to remake target 'src/bar.o'.
Finished prerequisites of target file 'src/exec'.
Prerequisite 'src/bar.o' is older than target 'src/exec'.
No need to remake target 'src/exec'.
Finished prerequisites of target file 'all'.
因此,让我们看到bar.h
比bar.o
更新,但是没有可用于构建bar.o
的配方,因此它对bar.o
没有任何作用.结果,请注意bar.o
的时间戳未更改,因此bar.o
并不比src/exec
更新,因此没有重建src/exec
.
So, make sees that bar.h
is newer than bar.o
, but there is no recipe available to build bar.o
, so it doesn't do anything with bar.o
. As a result, make notes that the timestamp for bar.o
has not changed, so bar.o
is not newer than src/exec
, so src/exec
is not rebuilt.
这篇关于Make不遵循依赖关系链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!