C/C++ Dependency Graphs

While working on my raytracer, I became curious as to what the dependency graph of my code looked like. To accomplish this, I wrote a Python script that will scan a given directory and generate the dependency graph as a PDF file. This graph can either help you find unnecessary dependencies, locate circular dependencies, or just satisfy your curiosity.




This script requires both Python 2.6 and dot. If you are running Ubuntu, you can install dot with:

sudo apt-get install graphviz

Running the script with python is done as follows:

python cppdepends.py dir outfile

Where dir contains the source tree you wish to generate a graph for, and outfile is the pdf file you wish to output to.

This program is located at http://github.com/nflath.cppdepends. If you have any suggestions or improvements, or even if you just used it, please let me know.

3 Responses to “C/C++ Dependency Graphs”

  1. Eric says:

    I like your script, and (since I’m not proficient with Python) can it be updated to color the “worst” includes?

  2. nflath says:

    Eric:
    Just did that :) check out http://github.com/nflath/cppdepends for the updated version.

    Let me know if you have any more suggestions!

  3. nflath.com says:

    Cc dependency graphs.. Slap-up :)

Leave a Reply