我的makefile文件如下:GNU作出不予刪除中間文件
# The names of targets that can be built. Used in the list of valid targets when no target is specified, and when building all targets.
TARGETS := libAurora.a libAurora.so
# The place to put the finished binaries.
TARGET_DIRECTORY := ./Binaries
# The compiler to use to compile the source code into object files.
COMPILER := g++
# Used when compiling source files into object files.
COMPILER_OPTIONS := -I. -Wall -Wextra -fPIC -g -O4
# The archiver to use to consolidate the object files into one library.
ARCHIVER := ar
# Options to be passed to the archiver.
ARCHIVER_OPTIONS := -r -c -s
SOURCE_FILES := $(shell find Source -type f -name *.cpp)
OBJECT_FILES := $(SOURCE_FILES:.cpp=.o)
.PHONY: Default # The default target, which gives instructions, can be called regardless of whether or not files need to be updated.
.INTERMEDIATE: $(OBJECT_FILES) # Specifying the object files as intermediates deletes them automatically after the build process.
Default:
@echo "Please specify a target, or use \"All\" to build all targets. Valid targets:"
@echo "$(TARGETS)"
All: $(TARGETS)
lib%.a: $(OBJECT_FILES)
$(ARCHIVER) $(ARCHIVER_OPTIONS) $(TARGET_DIRECTORY)/[email protected] $(OBJECT_FILES)
lib%.so: $(OBJECT_FILES)
$(ARCHIVER) $(ARCHIVER_OPTIONS) $(TARGET_DIRECTORY)/[email protected] $(OBJECT_FILES)
%.o:
$(COMPILER) $(COMPILER_OPTIONS) -c -o [email protected] $*.cpp
正如你所看到的,.o
文件被指定爲通過.INTERMEDIATE
目標中間體。但是,編譯完成後不會按預期方式刪除它們。相反,他們仍然在他們創建的地方,混亂了我的源代碼目錄。
奇怪的是,它在另一臺機器上完美工作。這導致我相信它是make
的不同版本,但man make
仍然將其顯示爲「GNU make實用程序」。
爲什麼make
刪除中間文件?
編輯:make -v
報告版本3.81。
編輯:手動刪除文件.o
(即一張白紙)後,make All
輸出如下:
g++ -I. -Wall -Wextra -fPIC -g -O4 -c -o Source/File/File.o Source/File/File.cpp
g++ -I. -Wall -Wextra -fPIC -g -O4 -c -o Source/Timer/Timer.o Source/Timer/Timer.cpp
ar -r -c -s ./Binaries/libAurora.a Source/File/File.o Source/Timer/Timer.o
ar -r -c -s ./Binaries/libAurora.so Source/File/File.o Source/Timer/Timer.o
您是否真的想在每次進行更改時重新構建所有源?如果它只是困擾你的'.o'噪音,那就把它們建在別的地方吧。並使用'make -v'來獲取版本。 – Mat
@Mat如果有更好的方式不涉及明確指定每個單獨的源文件,請告訴。 – Maxpm
運行時輸出「make All」是什麼? – Dan