我试图通过向vpath / VPATH添加源路径来使用我的Makefile(Make for Windows)。这似乎微不足道,但由于某种原因,我无法让它工作
我的目录结构如下:
├── Makefile
├── out\
└── src\
└── hello.cpp
我的Makefile是:
TGT=out
OBJ=hello.o
VPATH=src
# vpath %.cpp src
all: $(TGT)\app.exe
$(TGT)\app : $(TGT)\$(OBJ)
g++ $^ -o $@
$(TGT)\%.o : %.cpp
g++ -Wall -Wextra -Werror -c $<
更改为vpath并没有帮助我。我似乎在这里有一些根本错误的东西。我看到的错误是:
make: *** No rule to make target `out\hello.o', needed by `out\app'. Stop.
编辑:从make -d
Considering target file `all'.
File `all' does not exist.
No implicit rule found for `all'.
Considering target file `out\app'.
File `out\app' does not exist.
Considering target file `out\hello.o'.
File `out\hello.o' does not exist.
Looking for an implicit rule for `out\hello.o'.
Trying pattern rule with stem `hello'.
Looking for a rule with intermediate file `out\hello.cpp'.
Avoiding implicit rule recursion.
Trying pattern rule with stem `hello.cpp'.
No implicit rule found for `out\hello.o'.
Finished prerequisites of target file `out\hello.o'.
Must remake target `out\hello.o'.
答案 0 :(得分:1)
正如MadScientist所指出的,你应该避免使用反斜杠,因为它们有这样的奇怪结果,如果你在整个Makefile中使用正斜杠,你就不会遇到这个问题,那就说可以解决它们。
这里有一些问题:
all
之后的第一条规则应以$(TGT)\app.exe
作为目标。%
之前的反斜杠会将其转换为文字%
,转义反斜杠一旦你修复了所有这些,你应该发现vpath
按预期工作,完整的固定Makefile是
TGT=out
OBJ=hello.o
vpath %.cpp src
all: $(TGT)\app.exe
$(TGT)\app.exe : $(TGT)\$(OBJ)
g++ $^ -o $@
$(TGT)\\%.o : %.cpp
g++ -Wall -Wextra -Werror -c $< -o $@