Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing include dependencies

Does anyone know of a tool that will analyse a C++ codebase and display a graphical representation of which files include which header files and highlight redundant includes? I've used Understand C++ but it's expensive and became very unwieldy very quickly on a large (and poorly encapsulated) codebase.

like image 360
Mendokusai Avatar asked Sep 16 '26 18:09

Mendokusai


1 Answers

There's always the "-H" option to gcc/g++...

Eg.: % g++ -H foo.C

'-H'
     Print the name of each header file used, in addition to other
     normal activities.  Each name is indented to show how deep in the
     '#include' stack it is.  Precompiled header files are also
     printed, even if they are found to be invalid; an invalid
     precompiled header file is printed with '...x' and a valid one
     with '...!' .

Then:

  • 'sed' or 'awk' to remove the leading '...'.
  • 'sort to make same names adjacent.
  • 'uniq -c' to count names.
  • 'grep -v' to remove singletons.

As in:

%  g++ -H  foo.C |& awk '{print $2}' | sort | uniq -c | grep -v '      1 '

Or is that too linux'y / unix'y for you?

(Under windows, there's always cygwin.)

like image 86
Mr.Ree Avatar answered Sep 18 '26 08:09

Mr.Ree



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!