[英]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...然后按照包含顺序...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.