How to create Dependency Graphs for Header Files

I found these three Solutions for finding the dependencies graph for header files useful.
1) Manually: Manually one can write down on a piece of paper all the included headers of the given file in form of a graph. Keep on adding the nodes to each included file until it reaches an end. It’s a straight forward process for small projects and the advantage is we can clearly have track of all repeated headers and source files.

2) Microsoft Way: If you have Microsoft Visual studio Ultimate, Premium versions and Microsoft Visual studio 2010 feature pack 2, you can try this.

3) Open Source: Graphviz is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks. The Graphviz layout programs take descriptions of graphs in a simple text language, and make diagrams in useful formats, such as images and SVG for web pages, PDF or Postscript for inclusion in other documents; or display in an interactive graph browser. Graphviz has different tools to serve the purpose for many applications. Among them, dot tool which is a default tool generates graphs if edges have directionality. dot draws directed graphs as hierarchies. It runs as a command line program, web visualization service, or with a compatible graphical interface. Its features include well-tuned layout algorithms for placing nodes and edge, splines, edge labels, “record” shapes with “ports” for drawing data structures; cluster layouts; and an underlying file language for stream-oriented graph tools.
In order to make job easier we can use Doxygen software which provides a clean user interface for generating graphs using dot tool. Doxygen is a documentation system for C++, C, Java, Objective-C, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, PHP, C#, and to some extent D. Doxygen can use the “dot” tool from graphviz to generate more advanced diagrams and graphs.
How to use Doxygen for finding the for finding the dependencies graph for header files.
1) Install Doxygen
2) Open Doxywizard found in the installed programs.

3) After you open the GUI in step 1 : specify the working directory(create a separate folder for this)
4) Go to step 2 to Configure doxygen :
5) In step 2 choose wizard/ project. Set the source code directory and set scan recursively.
6) Set Destination directory(it can be same as working directory in step 1)
7) Go to wizard/Mode Select All entities button and optimize for c++ output button

8) Go to wizard/output deselect html (if you want the documentation in a html with all the class hierarchy select this option ) and select Latex and choose as intermediate format for hyperlinked pdf.

9) Go to wizard/Diagrams and set Use dot tool from the Graphviz package and select Include dependency graphs.

10) Now go to Expert tab and make sure only INCLUDE_GRAPH is checked. Make sure CLASS_GRAPH, COLLABORATION_GRAPH, GROUP_GRAPHS, INCLUDED_BY_GRAPH, CALL_GRAPH, CALLER_GRAPH and GRAPHICAL_HIERARCHY are unchecked.

11) Now go to run and hit Run deoxygen. Check the working directory for the dependencies graph outputs in pdf.

The elements in the graphs generated by the dot tool have the following meaning:
• A white box indicates a class or struct or file.
• A box with a red border indicates a node that has more arrows than are shown! In other words: the graph is truncated with respect to this node. The reason why a graph is sometimes truncated is to prevent images from becoming too large. For the graphs generated with dot doxygen tries to limit the width of the resulting image to 1024 pixels.
• A black box indicates that the class’ documentation is currently shown.
• A dark blue arrow indicates an include relation (for the include dependency graph) or public inheritance (for the other graphs).
• A dark green arrow indicates protected inheritance.
• A dark red arrow indicates private inheritance.
• A purple dashed arrow indicated a “usage” relation, the edge of the arrow is labeled with the variable(s) responsible for the relation. Class A uses class B, if class A has a member variable m of type C, where B is a subtype of C (e.g. C could be B, B*, T* ).

Make use of these graphs and find which files are included. Also, make sure to check the included headers even for the CPP source files. If a header ‘A’ includes another header file ‘B’ , make sure to consider the header files included in cpp file of B.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s