即使没有任何更改,Makefile 也始终不是最新的 [英] Makefile is always not up to date even without any changes
本文介绍了即使没有任何更改,Makefile 也始终不是最新的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个目录,其中包含两个文件夹, src
和 bin
,根目录中有makefile.即使没有更改,这个 makefile 也会继续编译(不是最新的).这个Makefile我缺少什么吗?
I have a directory with two folders, src
and bin
with the makefile at root directory. This makefile keeps compiling (not up to date) even without changes. Am I missing something with this makefile?
all:
make a b
a: ./src/a.cpp
g++ -o ./bin/a ./src/a.cpp
b: ./src/b.cpp
g++ -o ./bin/b ./src/b.cpp
推荐答案
您的规则声称可以创建文件 a
和 b
,但它们不是:它们创建 bin/a
和 bin/b
.
Your rules claim to create the files a
and b
, but they don't: They create bin/a
and bin/b
.
因此,当 make
检查您的规则时,它总是会发现 a
和 b
不存在,并尝试通过执行它们来创建它们关联的命令.
So when make
checks your rules, it always finds that a
and b
don't exist and tries to create them by executing their associated commands.
可能的解决方法:
.PHONY: all
all: bin/a bin/b
bin/a: src/a.cpp
g++ -o bin/a src/a.cpp
bin/b: src/b.cpp
g++ -o bin/b src/b.cpp
在 .PHONY
上:
查看全文