簡體   English   中英

如何知道符號來自的確切文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM