[英]Makefile error: No such file or directory
I've got this directory structure: 我有这个目录结构:
.\\src
contains all the source code ( .h
and .cpp
) .\\src
包含所有源代码( .h
和.cpp
) .\\bin
should have all the .o
and .bin
.\\bin
应该包含所有.o
和.bin
.
has Makefile
Makefile
This is my current Makefile: 这是我目前的Makefile:
CFLAGS = -Wall -pedantic -g
CC = g++
EXEC = flrfile
SRC_DIR = src
BIN_DIR = bin
SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ := $(patsubst $(SRC_DIR)/%,%,$(SOURCES))
OBJ := $(patsubst %.cpp,%.o,$(OBJ))
OBJ := $(addprefix ../$(BIN_DIR)/,$(OBJ))
all: flrfile
../$(BIN_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
$(CC) $(CFLAGS) -c $(SRC_DIR)/%.cpp -o $@
$(EXEC): $(OBJ)
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $(BIN_DIR)/$(OBJ) -o $(BIN_DIR)/$(EXEC)
.PHONY : clean
clean:
-rm -rf $(BIN_DIR)
When I run make
I get this error: 当我运行
make
我收到此错误:
g++ -Wall -pedantic -g -c src/%.cpp -o ../bin/FixedLengthFieldsRecord.o
g++: error: src/%.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
make: *** [../bin/FixedLengthFieldsRecord.o] Error 4
Why is this? 为什么是这样? I have little to no understanding of Makefile to be honest...
说实话,我对Makefile几乎没有理解......
The correct line for compiling should look like this: 正确的编译行应如下所示:
$(BIN_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
$(CXX) -o $@ -c $< $(CFLAGS)
Which means: "for every file matching the pattern "%.o" in $(BIN_DIR), compile it using the associated $(SRC_DIR)/%.cpp as argument (first dependency) 这意味着:“对于$(BIN_DIR)中匹配模式”%.o“的每个文件,使用关联的$(SRC_DIR)/%。cpp作为参数进行编译(第一个依赖项)
Additional comment: I suspect some missing dependencies: usually, a .c or cpp source file doesn't only depend on the corresponding header file, but might also include other headers from the project. 附加说明:我怀疑有些缺少依赖项:通常,.c或cpp源文件不仅依赖于相应的头文件,还可能包含项目中的其他头文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.