我正在尝试编译一个大型C++项目,其中包含src的几个子目录中的源文件。
我的Makefile看起来如下:
# ---------- Compiler and linker directives ----------
CXX = g++-11
CXXFLAGS = -std=c++17 -fopenmp -MD -g -Wall -pedantic
# LDFLAGS = -Wl,--gc-sections
# Output directory after linking
BIN_PATH = ../bin
BUILD_PATH = ../build
# ------- System Include --------------
# Change ~/include as necessary for your architecture
INC_FLAGS = -I../include -I/opt/homebrew/include
# -------- Establishing objects and sources ------
RATE_SRC = $(wildcard hartreefock/*.cpp) $(wildcard struct_hartreefock/*.cpp) $(wildcard numerical/*.cpp)
RATE_OBJ = $(addprefix $(BUILD_PATH)/,$(RATE_SRC:.cpp=.o)))
# ------------- Specific Include -----------
# RATE_HEADERS = $(wildcard hartreefock/*.hpp) $(wildcard struct_hartreefock/*.hpp) $(wildcard numerical/*.hpp)
RATE_DIR = hartreefock struct_hartreefock numerical
RATE_INC = $(addprefix -I,$(RATE_DIR))
# ---------- Libraries needed for linking ----------
# Change or remove ~/lib as necessary for your architecture
LIB_PATH = -L/opt/homebrew/lib
# Generic .cc -> .o rule
$(BUILD_PATH)/%.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INC_FLAGS) $(RATE_INC) $< -c -o $@
# ---------- Linking rules ----------
# Generic .o -> exec rule: uses all prerequisites (meant to be .o files)
ratecalc: $(RATE_OBJ)
$(CXX) $(CXXFLAGS) $(INC_PATH) $(A_RATE_INC) $(LDFLAGS) $^ \
$(LIB_PATH) -o $(BIN_PATH)/$@
# TODO
# simulate:
echo:
echo "$(RATE_OBJ)"
echo "$(BUILD_PATH)"
# Cleanup:
.PHONY: clean build_directories
clean:
-rm -r $(BUILD_PATH)/**奇怪的是,在我找到一个特定的文件之前,这似乎是正确的:
make clean
make ratecalc
g++-11 -std=c++17 -fopenmp -MD -g -Wall -pedantic -I../include -I/opt/homebrew/include -Ihartreefock -Istruct_hartreefock -Inumerical struct_hartreefock/RateData.cpp -c -o ../build/struct_hartreefock/RateData.o
g++-11 -std=c++17 -fopenmp -MD -g -Wall -pedantic -I../include -I/opt/homebrew/include -Ihartreefock -Istruct_hartreefock -Inumerical numerical/Constant.cpp -c -o ../build/numerical/Constant.o
make: *** No rule to make target `../build/numerical/wignerSymbols.o)', needed by `ratecalc'. Stop.这特别奇怪,因为Constant.cpp和wignerSymbols.cpp位于同一个目录中。与此目标一起手动运行时,将根据需要编译对象文件,
make ../build/numerical/wignerSymbols.o
g++-11 -std=c++17 -fopenmp -MD -g -Wall -pedantic -I../include -I/opt/homebrew/include -Ihartreefock -Istruct_hartreefock -Inumerical numerical/wignerSymbols.cpp -c -o ../build/numerical/wignerSymbols.o但这并不能满足ratecalc规则的依赖性。
wignerSymbols.cpp是RATE_OBJ中的最后一个条目,这可能很重要,但老实说,我不明白这里发生了什么。
为了完整起见:我在M1 macbook上使用GNUmake3.81。
发布于 2022-04-19 13:10:19
错误:
RATE_OBJ = $(addprefix $(BUILD_PATH)/,$(RATE_SRC:.cpp=.o)))这里有一个非常接近的paren,您可以在错误消息中看到这一点:
make: *** No rule to make target `../build/numerical/wignerSymbols.o)', ...https://stackoverflow.com/questions/71923677
复制相似问题