make:找不到包含的用户定义的头文件?

问题描述 投票:0回答:1

[运行make时,出现以下错误:

make: *** No rule to make target Menu.h', needed by Menu.o'. Stop.

这是我的Makefile:

PROG = sim
CURR_PATH = ~/Projects/restaurant/cpp/
CC = g++
CPPFLAGS = -g -v -Wall $(LOCAL_INCLUDES) -I$(BOOST_ROOT)
ODIR = ./bin
SDIR = ./src
LOCAL_INCLUDES = $(patsubst %,-I$(CURR_PATH)src/%,$(PKG_DIRS))
PKG_DIRS = $(shell ls $(SDIR))
FIND_SRC_FILES = $(notdir $(wildcard $(SDIR)/$(pkg)/*.cpp))
SRC_FILES = $(foreach pkg,$(PKG_DIRS),$(FIND_SRC_FILES))
OBJ_FILES = $(patsubst %.cpp,%.o,$(SRC_FILES))
MAIN_OBJ = main.o

.PHONY : prog

prog : $(PROG)

all : ; $(info $$CPPFLAGS is [${CPPFLAGS}])@echo Hello world

$(PROG) : $(OBJ_FILES)
    $(CC) $(CPPFLAGS) -o $(PROG) $(MAIN_OBJ)
%.o : %.cpp
    $(CC) $(CPPFLAGS) -c $< -o $@
$(OBJ_FILES) : %.o : %.h
    $(CC) $(CPPFLAGS) -c $(patsubst %.h,%.cpp,$<) -o $@

顺便说一句,如果您想知道LOCAL_INCLUDES是什么样的,那么'all'配方的输出如下:

$CPPFLAGS is [-g -v -Wall -I~/Projects/restaurant/cpp/src/concurrent -I~/Projects/restaurant/cpp/src/containers -I~/Projects/restaurant/cpp/src/data -I~/Projects/restaurant/cpp/src/loader -I~/Projects/restaurant/cpp/src/main -I~/Projects/restaurant/cpp/src/people -I~/Projects/restaurant/cpp/src/sim -I/usr/local/boost_1_72_0]
Hello world

很抱歉,单行输出,我不知道如何以更易读的方式设置格式。但是如您所见,目录[[data包含Menu.h,已被正确包含。但是由于某种原因,make无法找到它。这里可能出了什么问题?

让我知道是否需要更多信息。

欢呼声

c++ makefile
1个回答
0
投票
The

compiler知道如何找到该头文件。 Make不知道如何找到它,Make是产生该错误消息的人。

我建议您进行此修改:

INCLUDE_DIRS = $(addprefix $(CURR_PATH)src/,$(PKG_DIRS)) LOCAL_INCLUDES = $(addprefix -I,$(INCLUDE_DIRS)) vpath %.h $(INCLUDE_DIRS)

(P.S。您对CURR_PATH.的使用令人困惑,并且data/是放置标头文件的糟糕地方。)
© www.soinside.com 2019 - 2024. All rights reserved.