I am leading a large C ++ project in Visual Studio 2010 (pure C ++ / WinAPI), and recently there has been a need to use precompiled headers.

There are a couple of files that rarely change (at least once every 4 days or more) and are included everywhere. When you change their contents, you have to recompile the entire project, which can take about 15 minutes on a slow machine.

When creating a precompiled header, I encounter another problem - the #include directive of the header file must be specified in all files that exist in the project. But my project contains several open source libraries, the contents of which I don’t want to change because of the need to periodically update these libraries.

Therefore, I get C1010 errors : unexpected end of file while searching for a precompiled header. You may have forgotten to add the "#include name" directive to the source .

Perhaps there is a way to tell the environment that my precompiled header file should be included in all default files automatically? Is there a way to use precompiled headers in my case?

  • Not understood. You say that you use extraneous libraries. But what's stopping you from generally turning off the use of precompiled headers there? - AnT

2 answers 2

You can not register in all files #include "stdafx.h", but use the mechanism "Forced Included File".

Go to the settings tab «Advanced». Select all configurations. In the field “Forced Included File” we write:

StdAfx.h;% (ForcedIncludeFiles)

Now "stdafx.h" will automatically be included in the beginning of ALL compiled files. PROFIT!

You no longer need to write #include "stdafx.h" at the beginning of all .c / .cpp files. The compiler will do it by itself.

Taken from here https://habr.com/company/pvs-studio/blog/227521/

    The #include directive of the header file must be specified in all files existing in the project.

    No, this #include directive should be specified only in those files for which the setting "Use precompiled headers" is enabled. This setting is controlled to an individual file. If you have files (or projects) in which for some reason you don’t want to include this #include directive, just turn off pre-compiled headers for them individually.

    I do not quite understand your mention of extraneous libraries. You don’t modify extraneous libraries, do not depend on your headers, for which reason they only compile once and do not require frequent recompilation. Accordingly, it makes no sense for them to use precompiled headers. Just turn off precompiled headers for them and that's it.