0

Do you ever have a .h that you know is being included by another .cpp, but not directly, and you can't for the life of you figure out how said .cpp is including the .h? You'll have straightforward situations like: Car.cpp => Car.h, or you can have a whole maze of inclusions, where you know that Car.cpp is including ImportantHeader.h, but the dependency goes something like: Car.cpp => ??? => ImportantHeader.h, and you want to know how it's including ImportantHeader.h

Car.cpp is including tons of other headers, which in turn are including a bunch of other headers, so finding out what the "include path" from Car.cpp to ImportantHeader.h is is a daunting task.

Do you know of any useful tricks or tools for finding out this information?

NickLokarno
  • 300
  • 6
  • 20
  • Some IDE's can help with this kind of thing. For example https://stackoverflow.com/questions/3069182/how-can-i-see-the-c-c-include-graph-easily – Cory Kramer Sep 23 '20 at 16:35
  • 2
    Temporarily remove the .h file and compile. The error message(s) will tell you where it is being included from. – Richard Critten Sep 23 '20 at 16:35
  • Usually `grep` or `git grep` if not just "Find" in your favourite editor. If it has a unique name should be easy to pinpoint. C++ doesn't have dynamic inclusion so you can't really hide it. – tadman Sep 23 '20 at 17:38

0 Answers0