I have one .cpp file that includes a few header files. These header files may include other header files as well. Include guards are in place to prevent including the same file twice.
Knowing that each file is only included once. Is there a way to figure out the eventual order in which all headers will be included?
I tried gcc -E to get the preprocessor output, but the generated code doesn’t seem usable for extracting the information that I want. Can anyone help?
Edit
The reason why I’m asking is because I need to include my header files in a SWIG interface file in the correct order to avoid generation of weird SWIGTYPE_p_* wrappers.
Update
Thanks for the answers. Using cpp -H seems very useful. However, I can’t find way to grep or sed these results in order to get the simple list of header files in the correct order and without duplicates.
Use
cpp -H. This prints the headers used to standard error. Example:See the GNU cpp manual for details.
EDIT Here’s a small Python script that will show the order of inclusion, assuming all headers have include guards:
(You should be able to translate this to Awk or Perl if Python is not your cup of tea.)