makefile - GNU 制造商 : warning: ignoring old commands for target `xxx'

标签 makefile gnu-make

您能帮我理解 GNU Make(版本 3.81)如何处理简单的 Makefile 吗?这是文件:

.PHONY: a b c e f
a : b c
    @echo "> a(b,c)"
e : a
    @echo "> e(a)"
e : f
    @echo "> e(f)"
f :
    @echo "> f()"
b :
    @echo "> b()"
c :
    @echo "> c()"

现在我运行命令

make e

构建“e”目标。 Make 的输出如下所示:

Makefile:7: warning: overriding commands for target `e'
Makefile:5: warning: ignoring old commands for target `e'
> f()
> b()
> c()
> a(b,c)
> e(f)

http://www.gnu.org/software/make/manual/html_node/Error-Messages.html给出下一个解释:

‘warning: overriding recipe for target `xxx'’

‘warning: ignoring old recipe for target `xxx'’

GNU make allows only one recipe to be specified per target (except for double-colon rules). If you give a recipe for a target which already has been defined to have one, this warning is issued and the second recipe will overwrite the first.

但是从输出中我们可以看到构建“a”目标的命令也被执行。我认为根据“错误消息”页面 make 的描述,在处理此 Makefile 并尝试构建“e”目标(make e)时,应该首先决定“e”依赖于“a”,然后覆盖此'e' 取决于 'f'。输出应如下所示:

Makefile:7: warning: overriding commands for target `e'
Makefile:5: warning: ignoring old commands for target `e'
> f()
> e(f)

但看起来 make 仍然记得“e”依赖于“a”并且根本不覆盖配方。

请帮助我理解这种行为。为什么即使在配方覆盖之后,构建“a”目标的命令仍然执行?

最佳答案

依赖关系与命令不同。对 a 的依赖不会被忘记,但命令会被忘记。

关于makefile - GNU 制造商 : warning: ignoring old commands for target `xxx' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127119/

相关文章:

makefile - 在 GNU Make 中加入列表的元素

docker - 在传递给 docker run 命令的变量中转义 $

linux - Makefile PHONY 在大文件中的使用

c - 使用 gnu-make 链接静态库时如何遵循链接顺序?

makefile - Makefile 中的双冒号规则是什么?

c - make 使用 autotools 给出 undefined reference 错误,而自定义 Makefile 工作正常

makefile - 如何修复我的makefile?

c - "make all"连续两次不 't return "使 : Nothing to be done for 'all' . "

c++ - 为什么我的makefile文件返回错误193?

c++ - 运行 make 时附加编译器标志