【发布时间】:2018-06-02 14:18:42
【问题描述】:
这是我人生中的第一个makefile!我有一个项目,其中有 src 文件夹(我保存我的 .cpp 文件),一个 include 文件夹(我保存我的 .hpp 文件)和我想在其中存储我的目标文件的 build 文件夹。
# define the C compiler to use
CCXX = g++ -std=c++11
# define any compile-time flags
CXXFLAGS = -g -Wall
# define any directories containing header files other than /usr/include
INCLUDES = -I./include
#define the directory for src files
SRCDIR = ./src/
#define the directive for object files
OBJDIR = ./build/
# define the C source files
SRCS = action.cpp conditionedBT.cpp control_flow_node.cpp execution_node.cpp main.cpp
# define the C object files
OBJS = $(OBJDIR)$(SRCS:.cpp=.o)
# define the executable file
MAIN = out
.PHONY: depend
all: $(MAIN)
@echo Program compiled
$(MAIN): $(OBJS)
$(CCXX) $(CXXFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS)
$(OBJDIR)/%.o: ($SRCDIR)/%.c
$(CCXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
#.c.o:
# $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
#clean:
# $(RM) *.o *~ $(MAIN)
depend: $(addprefix $(SRCDIR),$(SRCS))
makedepend $(INCLUDES) $^
# DO NOT DELETE THIS LINE -- make depend needs it
鉴于上述情况,当我尝试执行 make 时出现以下错误:
make: *** No rule to make target `build/action.o', needed by `out'. Stop.
【问题讨论】:
-
.c与.cpp不同。 -
CC,CFLAGS用于 C,因此默认规则也不会拾取它。最好使用CXX、CXXFLAGS。