在 Visual Studio 中显示 C++ 文件的 #include 层次结构

2021-12-07 00:00:00 visual-studio include c++

问题:我有一个大型 Visual C++ 项目,我正尝试将其迁移到 Visual Studio 2010.它包含来自不同来源和不同时代的大量内容.我遇到了问题,因为某些内容同时包含 winsock.hwinsock2.h.

Problem: I have a large Visual C++ project that I'm trying to migrate to Visual Studio 2010. It's a huge mix of stuff from various sources and of various ages. I'm getting problems because something is including both winsock.h and winsock2.h.

问题:有哪些工具和技术可以显示 Visual Studio C++ 源文件的 #include 层次结构?

Question: What tools and techniques are there for displaying the #include hierarchy for a Visual Studio C++ source file?

我知道 cl/P 用于获取预处理器输出,但这并没有清楚地显示哪个文件包含哪些其他文件(在这种情况下,/P 输出是 376,932 行 8-)

I know about cl /P for getting the preprocessor output, but that doesn't clearly show which file includes which other files (and in this case the /P output is 376,932 lines long 8-)

在一个完美的世界中,我想要分层显示哪些文件包含哪些其他文件,以及行号,以便我可以跳转到源代码:

In a perfect world I'd like a hierarchical display of which files include which other files, along with line numbers so I can jump into the sources:

source.cpp(1)
  windows.h(100)
    winsock.h
  some_other_thing.h(1234)
    winsock2.h

推荐答案

有个设置:

项目设置 -> 配置属性 -> C/C++ -> 高级 -> 显示包含

Project Settings -> Configuration Properties -> C/C++ -> Advanced -> Show Includes

这将生成树.它映射到编译器开关 /showIncludes

that will generate the tree. It maps to the compiler switch /showIncludes

相关文章