I clone a repo, c++ solution with 3 projects, a console application .exe
a dll project .dll
and a unit test .dll
. I am not sure with what version of VS or compiler it was built or created.
building the solution on my machine was throwing erro
unexpected end of file while looking for precompiled header. Did you forge t to add '#include "pch.h"' to your source?
I created pch.h
and pch.cpp
according to another solution in every project.
changed the properties->c/c++->precompiled headers
of every project to
precompiled header = Create (/Yc)
precompiled header file = pch.h
precompiled header output file = $(IntDir)$(TargetName).pch
cleared solution and deleted every thing in Debug
folders
now building the solution throws
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forge t to add '#include "stdafx.h"' to your source?
- Also this was the Error Azure pipelines were showing. so to be close to build process of pipeline I use
msbuild.exe
from VS commandline. The weird part for me is that the VC++ right click on solution and build, does not show any error and build project, and after that msbuild.exe also rebuilds without error. But deleting everything from Debug folders and re-trying msbuild.exe shows these errors again!
How should I force all projects in a solution to use stdafx.h
or pch.h
The precompiled headers are a feature to speed up the build process, so if you have trouble building, you can always turn off the precompiled headers (select 'Not using precompiled headers' in the project settings for the whole project) and the build should work.
If you want to make the project build with precompiled headers, you should have the 'Create' option on for only one source file (pch.cpp or stdafx.cpp) that only contains the include statement for the precompiled header file. All the other source files should have the 'use' precompiled headers selection on. Also they must have the correct #include statement for your precompiled header as the 1st non-comment line in the file.
The idea is that the compiler makes a dump of its internal state when processing the precompiled header #include statement in the file with the 'create' option set. It then loads that dump when it sees the corresponding include in the files with the 'use' option turned on. Loading the dump can be much faster than e.g. parsing through windows.h. So yo should put any commonly used large header file #include statements in the pch.h or stdafx.h.
The error messages you got are produced if the .cpp file has the 'use' option on, but the #include statement with the file name set in the 'precompiled header file' option is not found.