英文:
Phony targets not working on windows make
问题
我正在尝试在make上创建一个虚假目标,以便我的“all”目标即使先决文件未更改也不会每次运行,但是每次运行时make仍然会运行每个目标。
以下是一个示例Makefile:
CXX = g++
CXXFLAGS = -Wall
.PHONY: all
all: testing testing2
testing: testing.cpp
testing2: testing2.cpp
clean:
del *.exe *.o
由于使用了.PHONY将all声明为虚假目标,预期结果是通过运行make,只有当目标的结果(testing.exe和testing2.exe)比它们的先决条件(testing.cpp和testing2.cpp)旧时,才会运行“testing”和“testing2”目标。然而,每次运行make时,两个目标也会运行。我在Windows上使用通过chocolatey安装的make,make --version是GNU Make 4.3 适用于Windows32。
虚假目标在Windows上的make是否不起作用?
英文:
I am trying to make a phony target on make so that my "all" target doesn't run every time even if the prerequisite files haven't changed, but make still runs every target every time I run it.
Here is an example Makefile:
CXX = g++
CXXFLAGS = -Wall
.PHONY: all
all: testing testing2
testing: testing.cpp
testing2: testing2.cpp
clean:
del *.exe *.o
The due to declaring all as a phony target using .PHONY, the intended result is that by running make, the "testing" and "testing2" targets should only be ran if their respective results (testing.exe and testing2.exe) are older than their prerequisites (testing.cpp and testing2.cpp). However, every time make is run, both targets are ran as well. I am using make on windows installed via chocolatey, make --version is GNU Make 4.3 Built for Windows32.
Do phony targets not work on make windows?
答案1
得分: 3
你的规则表明你要构建文件 testing
和 testing2
。但你的配方实际上构建了文件 testing.exe
和 testing2.exe
。
因此,当 make 运行时,它会查找文件 testing
,以查看它是否是最新的,但它并不存在,因此 make 运行配方,构建 testing.exe
。然后下次运行 make 时,它仍然查找文件 testing
,发现它不存在,所以继续运行配方,构建 testing.exe
,依此类推。
这与 PHONY 无关,PHONY 只适用于 all
,所以为什么会与重新构建 testing
有关呢?
你需要在 make 中使用与配方创建的文件同名的目标名称。
英文:
Your rules say you'll build the files testing
and testing2
. But your recipes don't build those files, they build the files testing.exe
and testing2.exe
.
So when make runs, it looks for the file testing
to see if it's up to date and it doesn't exist, so make runs the recipe, which builds testing.exe
. Then the next time make runs, it looks for the file testing
to see if it's up to date and it doesn't exist, so make runs the recipe, which builds testing.exe
. Etc. etc.
This has nothing to do with PHONY which only applies to all
so why would it be related to rebuilding testing
?
You need to name your targets in make with the same name of the file that your recipe creates.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论