Do we have any option in gcc to find from where a particular file header is included. I have the following scenario :
我们在gcc中有任何选项可以找到包含特定文件头的位置。我有以下情况:
file_1.h : declare type of type_1
file_1.h:声明type_1类型
file_2.h :
type_1 var;
I want to check where was file_1.h included in the library that i am creating.
我想检查我正在创建的库中包含的file_1.h.
2 个解决方案
#1
9
gcc has an option -M:
gcc有一个选项-M:
-M Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.
-M不输出预处理结果,而是输出适合描述主源文件依赖关系的规则。预处理器输出一个make规则,其中包含该源文件的目标文件名,冒号以及所有包含文件的名称,包括来自-include或-imacros命令行选项的文件。
If you do, gcc -M filename.c
, it'll list out all headers. Same with g++.
如果你这样做,gcc -M filename.c,它会列出所有标题。与g ++相同。
#2
0
If you look at the preprocessed output it will show the headers that were included, in the order they were included, so you can see where file_1.h appears and work backwards to see which file included it, and which file included that etc.
如果查看预处理的输出,它将按照它们被包含的顺序显示所包含的标题,这样您就可以看到file_1.h出现在哪里并向后工作以查看包含它的文件以及包含该文件的文件等。
The -E
option tells GCC to only perform the preprocessing step and to stop before compilation.
-E选项告诉GCC仅执行预处理步骤并在编译之前停止。
#1
9
gcc has an option -M:
gcc有一个选项-M:
-M Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.
-M不输出预处理结果,而是输出适合描述主源文件依赖关系的规则。预处理器输出一个make规则,其中包含该源文件的目标文件名,冒号以及所有包含文件的名称,包括来自-include或-imacros命令行选项的文件。
If you do, gcc -M filename.c
, it'll list out all headers. Same with g++.
如果你这样做,gcc -M filename.c,它会列出所有标题。与g ++相同。
#2
0
If you look at the preprocessed output it will show the headers that were included, in the order they were included, so you can see where file_1.h appears and work backwards to see which file included it, and which file included that etc.
如果查看预处理的输出,它将按照它们被包含的顺序显示所包含的标题,这样您就可以看到file_1.h出现在哪里并向后工作以查看包含它的文件以及包含该文件的文件等。
The -E
option tells GCC to only perform the preprocessing step and to stop before compilation.
-E选项告诉GCC仅执行预处理步骤并在编译之前停止。