【发布时间】:2017-08-09 09:31:33
【问题描述】:
我的项目中有 2 个目录,一个名为 Builds,它拥有 Makefile 和一个测试程序 (test-P0-consola.cpp),另一个名为 P0 的目录包含我使用的类 cadena (string) 和fecha(日期)。
test-P0-consola.cpp 包含它们,但 Make 没有找到它们。
CPP = g++
CPPFLAGS = -std=c++14 -g -Wall -pedantic
VPATH = ../P0:.:..
test-consola: test-P0-consola.o fecha.o cadena.o
${CPP} ${CPPFLAGS} -o $@.ex $^
test-P0-consola.o: test-P0-consola.cpp fecha.hpp cadena.hpp
${CPP} -c ${CPPFLAGS} $< -o $@
fecha.o: fecha.hpp
cadena.o: cadena.hpp
当它试图编译 test-P0-consola.o 时,它会抛出致命错误“cadena.hpp 不存在文件或目录”,但是当我强制它编译 cadena 或 fecha 时它会发现它们。我正在使用 GCC 和 Ubuntu。
..
├── Builds
│ ├── makefile.mak
│ └── test-P0-consola.cpp
├── P0
│ ├── cadena.cpp
│ ├── cadena.hpp
│ ├── fecha.cpp
│ └── fecha.hpp
编辑
错误:
g++ -std=c++14 -g -Wall -pedantic -c test-P0-consola.cpp
test-P0-consola.cpp:7:21: fatal error: fecha.hpp: There is no file or directory
compilation terminated.
makefile.mak:9: Failure in the instructions for the objective 'test-P0-consola.o'
make: *** [test-P0-consola.o] Error 1
【问题讨论】:
-
你能描述一下你正在做的具体错误和具体构建,并在构建开始时打印完整的目录树吗?目前还不清楚错误是什么。
-
我添加了完整的错误以及目录树。我只是想执行一个测试来检查类是否有错误。如果你在同一个文件夹中编译它们就可以了。