gcc -M 选项

-M Instead of outputting the result of preprocessing, output a rule suitable for make
describing the dependencies of the main source fle. The preprocessor outputs
one make rule containing the object fle name for that source fle, a colon, and
the names of all the included fles, including those coming from ‘-include’ or
‘-imacros’ command line options.
Unless specifed explicitly (with ‘-MT’ or ‘-MQ’), the object fle name consists of
the name of the source fle with any sufx replaced with object fle sufx and
with any leading directory parts removed. If there are many included fles then
the rule is split into several lines using ‘\’-newline. The rule has no commands.
This option does not suppress the preprocessor’s debug output, such as ‘-dM’.
To avoid mixing such debug output with the dependency rules you should explicitly specify the dependency output fle with ‘-MF’, or use an environment
variable like DEPENDENCIES_OUTPUT (see Section 3.19 [Environment Variables],
page 310). Debug output will still be sent to the regular output stream as
normal.
Passing ‘-M’ to the driver implies ‘-E’, and suppresses warnings with an implicit
‘-w’.

翻译:

-M选项用来生成源文件的依赖关系,预处理器生成一个这样的规则->

对象文件名称:所有依赖的包含文件

对象文件名称包含源文件的文件名+目标文件后缀(.o),并且删除源文件前的所有路径。如果有多个包含文件,则生成的规则通过 '\' 分割为多行。这条规则不包含命令。-M指令不限制预处理器的调试输出,为了不让调试输出与依赖关系打印混淆,需要使用-MF选项指定输出文件。调试信息仍旧正查过打印输出。-M选项默认使用了-E选项,并且使用了一个隐含的-w选项来抑制警告输出 。

例子:

#include 
#include "test.h"

int main()
{
    return 0;
}

执行 gcc -M test.c,输出如下 

test.o: test.c /usr/include/stdc-predef.h /usr/include/stdio.h \
 /usr/include/features.h /usr/include/sys/cdefs.h \
 /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
 /usr/include/gnu/stubs-64.h \
 /usr/lib/gcc/x86_64-redhat-linux/5.3.1/include/stddef.h \
 /usr/include/bits/types.h /usr/include/bits/typesizes.h \
 /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
 /usr/lib/gcc/x86_64-redhat-linux/5.3.1/include/stdarg.h \
 /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h test.h

 

你可能感兴趣的:(gcc)