Module Dependency Scanner

I wrote a little Perl script to scan a bunch of C/C++ source files and extract a graph of inter-module dependencies, both compile-time (e.g. #includes) and link-time.

The script: (alternate link for inline browsing). This script is still evolving, but the version here is quite usable.

Usage Information:

  usage: ./ [options] sourcefile [sourcefile ...]

  This program reads each of the source files specified on the command
  line, and emits a graph of their interdependencies in the Dot graph
  file format.  The source files should *not* be qualified with a path,
  but instead be inside some directory specified with -I.

    -I<dir>     Add <dir> to the list of directories to search when
                looking for #included files (files which are included
                but not found are not printed as dependencies).

    -X<name>    Exclude module <name> from the graph.  If a number is
    -X<name>=n  specified, at most that many incoming links will be shown.

    -S<name>    Do not process any outgoing edges from module <name>.  This
                is useful when <name> is the entry point to a subsystem
                whose dependencies are charted separately.

    -r          Recursively follow dependencies for files encountered.
    -q          Suppress warnings.
    -d          Enable debug messages.
    -h,-help    Print this usage string.

The dependency graph is output in the Dot format. Dot is responsible for laying out the graph in a comprehensible way. Information on Dot (including sources to download) can be found at

Example output is below. Compile-time dependencies are shown as solid arrows, and link-time dependencies are dashed arrows. Modules are circled, and header files are uncircled.

example dependency graph
Or, in postscript:

A small sample of related work: