如何轻松查看 C/C++ #include 图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3069182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I see the C/C++ #include graph easily?
提问by CannibalSmith
I'm looking for a tool (preferably, a Visual Studio plugin) that would display all files included by a given file and show all files included by those files and so on.
我正在寻找一种工具(最好是 Visual Studio 插件),它可以显示给定文件包含的所有文件并显示这些文件包含的所有文件等等。
采纳答案by kgiannakakis
回答by Allbite
First, cinclude2dot.plis a perl script which analyses C/C++ code and produces a #include dependency graph as a dot file for input into graphviz.
首先,cinclude2dot.pl是一个 perl 脚本,它分析 C/C++ 代码并生成#include 依赖关系图作为点文件以输入到 graphviz。
http://www.flourish.org/cinclude2dot/
http://www.flourish.org/cinclude2dot/
If you don't want to go the way of that sort of manual tool, then the hands-down by far winner is in my opinion a tool known as "IncludeManager" from ProFactor.
如果您不想走那种手动工具的道路,那么在我看来,迄今为止最成功的工具是ProFactor 的一个称为“ IncludeManager”的工具。
http://www.profactor.co.uk/includemanager.php
http://www.profactor.co.uk/includemanager.php
There's a free trial, and it is awesome. It's a plug-in for Visual Studio that's totally integrated so double clicking on something over heretakes you to the place where it is included over there.
有免费试用,很棒。这是一个插件,用于Visual Studio中是完全集成,因此双击的东西在这里把你带到它包括的地方在那里。
Tooltip mouseovers give you all the info you would want, and it lets you drill down / up, remove whole subtrees you don't care about, view representations other than graphs, cycle through a list of matches for this and that, it's wonderful.
工具提示鼠标悬停为您提供您想要的所有信息,它可以让您向下/向上钻取,删除您不关心的整个子树,查看除图表之外的表示,循环浏览此和那个的匹配列表,这太棒了。
If you're quick about it, you can refactor the #include structure of a large projects before the trial runs out. Even so, it doesn't cost much, about $35 per license.
如果您很快,您可以在试用期结束之前重构大型项目的#include 结构。即便如此,它的成本也不高,每个许可证大约 35 美元。
For what it does, it is just about perfect. Not only #include graphs but also cross project dependencies of shared files, impact on build times, detailed properties in grids, perfect.
对于它所做的,它几乎是完美的。不仅是#include 图表,还有共享文件的跨项目依赖,对构建时间的影响,网格中的详细属性,完美。
回答by icabod
Not quite what you want perhaps, but the Visual Studio compiler (cl.exe) has an option /showIncludes
which will show you a tree of the includes when you compile a file.
也许不是您想要的,但是 Visual Studio 编译器 (cl.exe) 有一个选项/showIncludes
,可以在您编译文件时向您显示包含树。
If you want this information for a single file then you can right-click on the file in the Solution Explorer, select "Properties", and in the "Command Line" section just add /showIncludes to the "Additional Options". (Note I'm using VC++ 2005, so it may be different for newer versions).
如果您需要单个文件的此信息,那么您可以在解决方案资源管理器中右键单击该文件,选择“属性”,然后在“命令行”部分中将 /showIncludes 添加到“附加选项”。(注意我使用的是 VC++ 2005,所以新版本可能会有所不同)。
The output that you get is a little... convoluted, but it shows you what gets included and in what order.
您得到的输出有点……令人费解,但它显示了包含的内容和顺序。
Incidentally, the same feature in GCC and the Intel C++ compiler (my versions at least) is -H
.
顺便说一句,GCC 和英特尔 C++ 编译器(至少我的版本)中的相同功能是-H
.
回答by wip
You can try the method suggested by this Stack Overflow answer:
您可以尝试此Stack Overflow 答案建议的方法:
There is a C/C++ -> Advanced project setting "show Includes". That will generate the tree. It maps to the compiler switch /showIncludes
有一个 C/C++ -> 高级项目设置“显示包含”。这将生成树。它映射到编译器开关/showIncludes
回答by Phil Devaney
If you are using Visual Studio 2010 you can use the new Visualization and Modelling Feature Packfrom Microsoft, which has a feature to generate an include graph. This is only available through an MSDN subscript though.
如果您使用的是 Visual Studio 2010,则可以使用来自 Microsoft的新可视化和建模功能包,它具有生成包含图的功能。不过,这只能通过 MSDN 下标获得。
回答by Jens Gustedt
Not in your preferences, but doxygen does that quite well.
不符合您的喜好,但 doxygen 做得很好。
回答by jdehaan
http://www.codeproject.com/KB/applications/includefinder.aspx
http://www.codeproject.com/KB/applications/includefinder.aspx
This is not a VS plug-in but can be a starter for your own tool. As far as I could see it reads VC6 projects only, the newer VS have an XML format easy to parse. What you need out of it are the default include paths so the tool can find the included files. Alternatively you could provide a settings box for it in the GUI as user input.
这不是 VS 插件,但可以作为您自己工具的入门。据我所知,它只能读取 VC6 项目,较新的 VS 具有易于解析的 XML 格式。您需要的是默认的包含路径,以便工具可以找到包含的文件。或者,您可以在 GUI 中为其提供一个设置框作为用户输入。