没有规则来制作目标.o,为什么?
No rule to make target .o, why?
这是我生命中的第一个制作文件!我有一个项目,其中有src文件夹(我在其中保存我的 .cpp 文件(、一个包含文件夹(我在其中保存我的 .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
相关文章:
- 当目标指针不是基类的类型时,为什么允许dynamic_cast为多态类生成 null 指针?
- 为什么子项目 CMAKE 不考虑 fno-sanitize,请禁用目标的消毒器
- 为什么即使链接器找到目标文件,我的程序也看不到函数定义?
- 没有规则来制作目标.o,为什么?
- 为什么即使目标数组很小,strcpy 也不会抛出错误?
- 当应该删除其目标时,为什么此智能指针给出正确的结果
- 为什么内部链接的名称会出现在我的目标文件的符号表中?
- 重复Handle()是否执行任何解释性通信(IPC),如果不是为什么目标参数
- Direct2D --- 为什么画笔资源绑定到各个 Direct2D 呈现目标
- 为什么不能重新分配引用的目标对象?
- 目标C++ 11 - 为什么我们不能给 lambda 分配一个块?
- 为什么GCC将对全局实例构造函数的调用放在不同的部分(取决于目标)
- 为什么在构建依赖库之前没有开始编译目标可执行文件?
- 为什么在c++中用shell链接查找快捷方式的目标路径时,它指的是windowsinstaller文件夹
- 为什么要链接多个目标文件,而不是一个大的目标文件
- Snprintf:当第二个参数超过目标内存时,为什么不报告错误
- 为什么我们要为c++应用程序构建64位目标?
- 为什么对某些Windows CE目标的编译在Visual Studio 2008中会"skipped"?
- 为什么boost::filesystem::canonical()要求目标路径存在?
- 当使用C++目标的释放模式时,为什么这个Haxe try-catch块仍然崩溃