Make不遵循依赖关系链

Make不遵循依赖关系链

本文介绍了Make不遵循依赖关系链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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 -MMmakedepend生成的*.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.hbar.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不遵循依赖关系链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:03