【发布时间】:2015-09-02 15:17:06
【问题描述】:
我的项目子目录中的 Makefile 只有在我的项目的主 Makefile 中使用时才看到包含路径。我对 Makefile 没有太多经验,而且我一直在阅读的很多内容都非常令人困惑。这是我的目录的布局(自从我刚刚开始项目以来我所拥有的):
main/
Inventory/
Item.h
Item.cpp
Makefile
tools/
include/
json/
json.h
jsoncpp.cpp
Makefile
main.cpp
Makefile
这是主目录中的Makefile:
INCLUDE = -IInventory/
CC = g++
DEP = tools/jsoncpp.o Inventory/Item.o
Main: main.o $(DEP)
cd tools/ && make
cd Inventory/ && make
$(CC) -o Main main.o $(DEP) $(INCLUDE)
main.o main.cpp
$(CC) -c main.cpp $(INCLUDE)
这是工具目录中的Makefile:
INCLUDE = -Iinclude/
CC = g++
jsoncpp.o: jsoncpp.cpp
$(CC) -c jsoncpp.cpp $(INCLUDE)
当我从 tools/ 调用 make 时,它工作得很好。但是当我从主目录调用 make 我得到这个错误:
g++ -c -o tools/jsoncpp.o tools/json.cpp
tools/jsoncpp.cpp:76:23: fatal error: json/json.h: No such file or directory
#include "json/json.h"
^
compilation terminated.
现在我部分地认为无论出于何种原因它都找不到包含目录,但由于 g++ 和 -c 之间存在奇怪的差距,该错误的第一行对我来说相当奇怪。由于我的项目很快就会变得很大,我该如何解决这个问题?
【问题讨论】: