-MM 标志在 g++ 中有什么作用?

What does the -MM flag do in g++?

我已经阅读了手册页上的解释(https://linux.die.net/man/1/g++),但我仍然不明白它的用例。我已经在下面的示例中看到它的使用:

g++ -MM -w --std=c++14 `pkg-config fuse3 --cflags` -fpermissive -I.. hello.cpp > .obj/hello.d

我想了解何时以及为何使用它。

您获得的 .obj/hello.d 文件可能如下所示。

hello.o: hello.cpp something.h stuff.h ...

这是 makefile 的依赖规则。

如果您的 makefile 使用类似

-include .obj/*.d

那就和你显式写这些依赖一样了

如果通用规则知道如何从相应的 .cpp 生成 .o,那么每次更改自动列出的头文件之一时都会触发它。