gpt4 book ai didi

makefile - makefile 中的 .PHONY 用法

转载 作者:行者123 更新时间:2023-12-03 05:09:19 28 4
gpt4 key购买 nike

在 makefile 中搜索 .PHONY 的用法时,我遇到了 this上面写着类似

.PHONY also allows you to have targets that do not have an associated rule

我将该帖子中提到的示例放入 makefile 中并运行了该文件,但它没有向我显示 OP 中提到的任何错误。有人可以详细说明一下吗?

生成文件

target1: dostuff

.PHONY: target2
target2: dostuff



dostuff:
@echo "Stuff gets done!!!!"

O/P

[sourav@titan temp]$ make target1
Stuff gets done!!!!
[sourav@titan temp]$ make target2
Stuff gets done!!!!
[sourav@titan temp]$ make
Stuff gets done!!!!
[sourav@titan temp]$

根据OP,make target1应该抛出一个错误。请赐教。

一些信息

[sourav@titan temp]$ uname -r
2.6.18-194.el5PAE
[sourav@titan temp]$ make --version
GNU Make 3.81
[sourav@titan temp]$

最佳答案

确实。 .PHONY 目标只能有依赖项,没有任何规则。在这种情况下,make不会执行任何规则,但会检查依赖关系是否满足(如果不满足,将执行它们的规则)。

因此,在您的示例中,target1target2 调用 dostuff 是正确的,因为它是依赖项。

关于makefile - makefile 中的 .PHONY 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352239/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com