How to find included header files using showIncludes

One of the irritating problems in practical C or C++ programming is finding out which are all the header files included when compiling a source file. This is true both when using the standard library or any other large library of header files.

Starting from a given source file, the header files it includes is a n-ary tree that can be many levels deep. When there is a compilation error due to something in one of these header files, the compiler only points to the file and line number. The programmer needs to figure out the path of header files from the source file being compiled to the final erroneous header file.

One solution is to index all the files automatically (Visual Studio or Eclipse) or manually (ctags) or use a documentation tool (Doxygen). You will still need to sift through their output and they might ignore compile-time macros that are defined or undefined during compilation.

A better solution is the /showIncludes compiler option in Visual C++ which greatly aids this investigation. Turn it on and it will print all the header files that are being processed while compiling a source file. It prints them out with indenting, so the nesting of header files is easy to see.

This option can also be turned on from Project Properties. Go to C++ -> Advanced.

Tried with: Visual Studio 2015 and Windows 7 x64

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s