make 忽略包含指令

make ignoring include directives

我正在使用 GNU make 并在我的 Makefile 中包含以下内容:

token_check: token_check.o $(STATIC_LIBRARIES)
    $(CC) -o $@ $^

%.o: %.c pipeline/*.h compiler/*.h
    $(CC) $(COMPILER_FLAGS) -I./pipeline -I./compiler -c $<

但是,当我运行make时,命令实际上运行是

cc -c -o token_check.o token_check.c

我得到了错误

token_check.c:3:10: fatal error: scanner.h: No such file or directory
    3 | #include "scanner.h"
      |          ^~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: token_check.o] Error 1

scanner.h 包含在编译器子目录中。

为什么我的 -I 指令被忽略了?

编辑:

我检查了一下,管道和编译器中都有头文件。

奇怪的是,即使我把菜谱换成

%.o: %.c pipeline/*.h compiler/*.h
    echo blah

和运行

make token_check.o

它仍然会尝试编译源文件,但“blah”永远不会被打印出来。

很可能 make 正在使用它的隐含规则,而不是你的。这样做很可能是因为您的模式规则不适用。一个原因可能是您在 pipeline.

中没有任何头文件