[英]Makefile builds everything each time
I have the following Makefile (reduced to ignore irrelevant stuff): 我有以下Makefile(减少为忽略无关的内容):
BUILD_DIR=./build
OBJS = \
$(BUILD_DIR)/main.o \
$(BUILD_DIR)/common.o \
...
roo: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LFLAGS)
.PHONY: $(BUILD_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)/passes
$(BUILD_DIR)/%.o: src/%.cpp $(BUILD_DIR)
$(CXX) -o $@ -c $< $(CFLAGS)
However, every object file is recompiled every time, even thought I'm following the rule to directly use $@
in each non-phony target. 但是,每次都会重新编译每个目标文件,甚至以为我遵循的规则是在每个非语音目标中直接使用$@
。
I don't think this is a duplicate of this because I'm applying the subdirectory in the rule rather than in the recipe, but I may be wrong? 我不认为这是一个重复的这个 ,因为我申请的子目录中的规则,而不是在食谱,但我可能是错了吗? How do I get Make to correctly track the dependencies in the build directory? 如何获得Make来正确跟踪构建目录中的依赖关系?
You've stated that $(BUILD_DIR)/%.o
depends on $(BUILD_DIR)
, but that directory will be touched every time a file is added to that directory (for example by this rule itself). 您已经说过$(BUILD_DIR)/%.o
取决于$(BUILD_DIR)
,但是每次将文件添加到该目录时都会触摸该目录(例如,此规则本身)。 That is, $(BUILD_DIR)
will always be newer than its target. 也就是说, $(BUILD_DIR)
将始终比其目标新。
It looks like you want to create the build directory automatically. 您似乎要自动创建构建目录。 The best way to do that, I think, is 我认为最好的方法是
$(BUILD_DIR)/%.o: src/%.cpp
mkdir -p $(BUILD_DIR)/passes
$(CXX) -o $@ -c $< $(CFLAGS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.