[英]No rule to make target .o, why?
这是我生命中的第一个文件! 我有一个项目,其中有src文件夹(其中保存我的.cpp文件), include文件夹(其中保存我的.hpp文件)和构建文件夹,我想要在其中存储目标文件。
# 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.
Makefile
存在一些问题。
1)当文件使用.cpp
时,您正在使用.c
扩展名。
2)您的替代指令OBJS = $(SRCS:.c=.o)
没有考虑源和对象的子目录。
3)创建对象的一般规则不是由于这些原因而被调用,还因为您未指定源的子目录。
因此, make
正在制定自己的规则来编译您的对象,而忽略了您制定的规则。
我也建议对C++
使用正确的隐式变量,这将使隐式规则更好地工作。
它们在这里详细说明: https : //www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
因此,我建议您更像这样:
# define the C compiler to use
CXX = g++
# define any compile-time flags
CXXFLAGS = -std=c++11 -g -Wall
# define any directories containing header files other than /usr/include
CPPFLAGS = -I./include
#define the directive for object files
OBJDIR = ./build
SRCDIR = ./src
# define the C source files
SRCS = $(SRCDIR)/action.cpp $(SRCDIR)/main.cpp
# define the C object files
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
# define the executable file
MAIN = out
.PHONY: depend
all: $(MAIN)
@echo Program compiled
$(MAIN): $(OBJS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(MAIN) $(OBJS)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@echo "Compiling: " $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
clean:
$(RM) $(OBJDIR)/*.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
# DO NOT DELETE THIS LINE -- make depend needs it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.