Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++: How to figure out the chain of header files for a given definition?

In Visual C++, one can find the header file where any name (variable or type) is defined by pressing F12 on it or choosing Go to Definition. This feature is very useful, but it only shows the final location (header file) where the name is defined. Is there a way to figure out the chain of header files that lead from my source file to the final header file for a given name?

For example, consider this code:

// main.cpp    
#include <stddef.h>
int main()
{
    size_t s;
    return 0;
}

In Visual C++ 2010, if I look up the definition of size_t in the above main.cpp, it lands me in some file named sourceannotations.h. I know that this header chain begins with stddef.h (which I have included) and ends in sourceannotations.h. How to figure out the links in the middle of this chain?

like image 742
Ashwin Nanjappa Avatar asked Jul 05 '10 06:07

Ashwin Nanjappa


3 Answers

  1. Right click project, "Project Properties"
  2. "Configuration Properties" -> "C/C++" -> "Advanced".
  3. Set "Show Includes" to "Yes".

The complete hierarchy of headers will be printed out in the output window when you compile every file.

like image 115
Alex B Avatar answered Oct 08 '22 06:10

Alex B


You can use reverse engineering tools like Doxygen, Understand Analyst etc. This will help you understand the full flow of variables, function calls.

like image 32
ckv Avatar answered Oct 08 '22 07:10

ckv


In your properties dialog, under C/C++, Preprocessor, enable Preprocess to a File. If you compile main.cpp, this will generate main.i.

You can then look in main.i and see which file includes what other file.

like image 1
R Samuel Klatchko Avatar answered Oct 08 '22 05:10

R Samuel Klatchko