【发布时间】:2020-06-29 13:14:20
【问题描述】:
我有以下目录结构(在 Ubuntu 上):
MyProject/
Here is my Makefile
MyProject/src/headers
Here are more subfolders and .hpp files
MyProject/src/sources
Here are two .cpp files (main.cpp and another.cpp)
所以我使用this 教程来编写我的makefile,如下所示:
cppsrc = $(wildcard src/sources/*.cpp)
obj = $(cppsrc:.cpp=.o)
flags = -I/usr/include/boost_1_72_0/ -pthread
cross: $(obj)
i686-atom-linux-gnu-g++ -o $@ $^ $(flags)
它检测子目录中的 .cpp 文件(耶!)。 但它不会检测 .cpp 文件中包含的头文件。所以我在 another.cpp 中包含了这样的标题:
#include "src/headers/another.hpp"
命令 make cross 给了我这个错误信息:
g++ -c -o src/sources/another.o src/sources/another.cpp
src/sources/another.cpp:6:10: fatal error: src/headers/another.hpp: No such file or directory
#include "src/headers/another.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'src/sources/another.o' failed
make: *** [src/sources/another.o] Error 1
错误信息让我相信makeapp会在这样的位置寻找头文件:
MyProject/src/sources/src/headers/
我的假设正确吗?我能做些什么来解决这个问题? 希望有人能帮助我。提前谢谢你。
【问题讨论】:
-
这与make无关。显示此错误的不是 make,而是编译器...如果您在 shell 提示符下自己运行该编译器调用,而无需 make,您将得到相同的错误。你需要问编译器是如何搜索头文件的。
-
感谢您的快速回复!所以我会去检查编译器文档。
标签: c++ makefile compilation cross-compiling