[英]How know the exact file the symbol comes from
我对包含文件有疑问。
假设您使用来自 windows 标头的定义。 当然,您可以知道定义宏的确切 header 是什么。 但问题是我们能否获得include
链并知道哪个路径导致宏被包含?
例如我有以下结构
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
如您所料,实际示例可能会因宏定义和ifdef
的音调而变得非常复杂。
现在在我们的example.cpp
中,我们#include "header4.h"
或#include "header5.h"
或两者一起使用 ant 我们在代码中使用windows.h
中的宏。 如何知道什么是包含链?
例如对于这个例子,它可能是header4.h - header1.h - windows.h
使用 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" ^~~~~~~
然后按照包含顺序...
我认为这个链接可以帮助你。 您可以 select Architecture->Generate Graph of Include Files/Generate Code Map for solution without Building
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.