I have a very big project and for the sake of compilation speed I started to test precompiled headers.
I've setup everything now:
StdAfx.h
only)StdAfx.h
StdAfx.h
in all my files via the force include of VSThe question that occurs now is following:
Do I need to remove all includes of all project files that I've added to the StdAfx.h
file or is this unnecessary? Will the compiler skip any include automatically because he knows it's part of the StdAfx.h
or should I remove them from each .h
/.cpp
file manually?
The good practice is to make each file include all the headers directly required by this file. This way changing includes in particular file should effect only this file. If you start depending on headers included somewhere else it will make your project structure extremely fragile. And the single "common includes" file is an extreme case of such scenario. Use of precompiled header supposed to speedup compilation by prebuilding commonly included header files, but project files should never assume that something is already included there. So there is no need need to remove includes from ".h/.cpp", actually there are some tools that will populate precompiled header based on includes in project files. Compiler will skip files already included in precompiled header (or in other headers) because of header guards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With