Makefile:已忽略模式规则

Makefile: ignored pattern rule

本文关键字:模式 规则 Makefile      更新时间:2023-10-16

我有一个C++项目需要头文件。我用python脚本从一些文件(.srv)构建了一些头文件。如果头丢失或srv文件发生了更改,我希望我的Makefile运行我的脚本。我在我的makefile中添加了这一行:

    include/services/%.h : include/srv/%.srv
        python headersFromSRV.py $<

当我试图构建我的项目时,我收到错误消息:

 fatal error: 'include/services/robot_device_list.h' file not found
 #include "include/services/robot_device_list.h"

这是逻辑,因为文件还不存在,但它不会调用规则来创建它。我的规则出了什么问题?

规则本身是可以的,但您的问题可能是makefile不知道它是一个需求。我猜错误消息来自您的C/C++编译器,该编译器正在构建其他目标。您可能需要添加robot_device_list.h作为该目标的依赖项,因此makefile知道他需要首先构建它。例如

foo.exe: foo.o
   (your link statement)
foo.o: foo.c include/services/robot_device_list.h
   (your compile statement)