简体   繁体   English

如何知道符号来自的确切文件

[英]How know the exact file the symbol comes from

I have a question regarding the include files.我对包含文件有疑问。

Suppose you are using a define coming from windows headers.假设您使用来自 windows 标头的定义。 Of course, you can know what is the exact header which defines the macro.当然,您可以知道定义宏的确切 header 是什么。 But the question is can we get the include chain and know which path causes the macro to be included?但问题是我们能否获得include链并知道哪个路径导致宏被包含?

Eg I have the following structure例如我有以下结构

windows.h // a windows header defines a macro

header1.h <- windows.h // a <- b means a includes b
header2.h <- windows.h
header3.h <- windoes.h
header4.h <- header1.h, header2.h
header5.h <- header1.h, header4.h, header3.h

As you would expect, the real example can be a lot complicated with tones of macro definitions and ifdef s.如您所料,实际示例可能会因宏定义和ifdef的音调而变得非常复杂。

Now in our example.cpp we #include "header4.h" or #include "header5.h" or both together ant we use the macro in windows.h in our code.现在在我们的example.cpp中,我们#include "header4.h"#include "header5.h"或两者一起使用 ant 我们在代码中使用windows.h中的宏。 How to know what is the include chain?如何知道什么是包含链?

Eg for this example it could be header4.h - header1.h - windows.h例如对于这个例子,它可能是header4.h - header1.h - windows.h

With gcc 6.3.0 you can use a #pragma trick使用 gcc 6.3.0,您可以使用#pragma技巧

$ cat so62875940.c
#include <stdio.h>
#pragma message "so62875940.c"

int main(void) {
    puts("foo");
    return 0;
}
$ gcc so62875940.c
so62875940.c:2:9: note: #pragma message: so62875940.c
 #pragma message "so62875940.c"
         ^~~~~~~

Then follow the includes order...然后按照包含顺序...

I think this link may help you.我认为这个链接可以帮助你。 You could select Architecture->Generate Graph of Include Files/Generate Code Map for solution without Building .您可以 select Architecture->Generate Graph of Include Files/Generate Code Map for solution without Building

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM