Finding how a header file gets included
6 May, 2010 § 2 Comments
Have you ever had a header file generate warnings that is not explicitly part of your Visual Studio solution?
Recently I’ve been working on fixing static analysis warnings reported by Microsoft’s PREfast static analysis tool for C++. I ran in to an issue though with some of the Microsoft Windows SDK v6.0 headers. One file, aptly named `
strsafe.h`, can be the cause for tons of warnings in a build.
I looked around and found that the Windows SDK team is fully aware of the problem. They recommend wrapping the include for
strsafe.h with pragmas, like so:
#include <CodeAnalysis/warnings.h> #pragma warning(push) #pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS) #include <strsafe.h> #pragma warning(pop)
So the first thing I did was to search through my code and find out who what included
strsafe.h. But it turns out that no file explicitly included it. I figured that it must get included from another include file.
To find out what files are included in your build, you can turn on
/showIncludes through the
Project Properties ➨ Configuration Properties ➨ C/C++ ➨ Advanced ➨ Show Includes
/showIncludes prints out a tree of all of the files that get included in when the project is built. Using this, I was able to find which SDK files we included that ended up including
This process took me about a half hour in total from turning the compiler flag on, performing a rebuild, narrowing down the includes, and wrapping them with pragmas. I still got a nasty taste in my mouth for suppressing the warnings, but getting rid of them cut out a lot of noise surrounding actual warnings that are more pressing.