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.
-
3dupe? http://stackoverflow.com/questions/42308/tool-to-track-include-dependencies – Johan Kotlinski Jun 18 '10 at 12:59
-
1Yes. My search fu has failed me. – CannibalSmith Jun 18 '10 at 13:42
-
@JohanKotlinski, I think that topic talks about just tracking the dependencies not about how to create a graph, an important difference IMO. – R Sahu Nov 15 '15 at 04:45
7 Answers
First, cinclude2dot.pl is a perl script which analyses C/C++ code and produces a #include dependency graph as a dot file for input into graphviz.
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.
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 here takes you to the place where it is included over there.
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.
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.

- 2,367
- 1
- 24
- 22
-
1IncludeManager looks like it does the trick easily, and is inexpensive. I'll give that one a shot. – Boinst Oct 01 '13 at 06:46
-
IncludeManager has been released for free, since they have stopped trading. – silver est Feb 11 '20 at 00:10
-
1`cinclude2dot` was the most useful for me to have a one-off look at the best header to include from a poorly-documented library. With graphviz command `~/scripts/cinclude2dot.pl | dot -Tsvg > output.svg` – MHebes Jan 12 '22 at 14:20
Doxygen, with the aid of Graphviz, can do that. You first need to edit a configuration file. This won't be easy the first time you do it, but no much editing is needed afterwards.

- 8,285
- 3
- 19
- 32

- 103,016
- 27
- 158
- 194
-
3Actually, it's simple in most cases - either use the Windows GUI of the Doxygen Wizard to generate it, or from the command line run `doxygen -g` to generate a default `Doxyfile` then ensure that you have the values `INCLUDE_GRAPH` and `INCLUDED_BY_GRAPH` set to `YES`. You might then need to run Doxygen a couple of times and check the output to tweak the parameters. – the_mandrill Jul 22 '13 at 09:13
-
Doxygen worked quite well, the windows gui version didn't need any config setup, just some info for the project, but the doc was ready in 2 mins after installation. I've let Graphviz to create a PATH env variable, probably it is needed, it asks for permission during installation creating it. – beatcoder Aug 09 '21 at 04:02
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.
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).
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
.

- 6,992
- 25
- 41
You can try the method suggested by this Stack Overflow answer:
There is a C/C++ -> Advanced project setting "show Includes". That will generate the tree. It maps to the compiler switch /showIncludes
If you are using Visual Studio 2010 you can use the new Visualization and Modelling Feature Pack from Microsoft, which has a feature to generate an include graph. This is only available through an MSDN subscript though.

- 21,988
- 13
- 81
- 109

- 17,607
- 6
- 41
- 33
-
If that is as useful a feature pack as it looks, this post deserves at least 100 upvotes. – James McNellis Jun 19 '10 at 04:22
-
From the screenshots the modelling feature pack indeed looks like a dream tool. However, you not only need a MSDN subscription but also a Premium or Ultimate Visual Studio to qualify for the download ;-( – BuschnicK May 26 '11 at 08:43
-
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.

- 19,700
- 6
- 57
- 97