Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precompiled headers - necessary to remove all precompiled headers from all other files

I have a very big project and for the sake of compilation speed I started to test precompiled headers.

I've setup everything now:

  • enable precompiled headers in VS (use them for the project, create it for the StdAfx.honly)
  • use multi processor compilation for all but for the StdAfx.h
  • automatically include the StdAfx.h in all my files via the force include of VS

The 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?

like image 218
prom85 Avatar asked Oct 18 '22 05:10

prom85


1 Answers

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.

like image 112
user7860670 Avatar answered Oct 20 '22 16:10

user7860670