0
votes

I'm using precompiled headers in my Visual Studio (2019) C++ project, and am including "pch.h" at the top of my source files, have #pragma once at the top of each header file, and a pch.cpp file (generated by the project template). Yet for one of the source files I get compiler error C1010: "Unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?" What other causes are there for this error?

1
Have you added #pragma once (include guard) on top of the header file?NutCracker
Yes, thanks, I should have mentioned that before; edited.voxoid
Have you tried this.NutCracker
I recommend backing up and then playing a few rounds of divide and conquer on the file that's giving you grief. If hacking the file down to a minimal reproducible example doesn't show you what the problem is, post the resulting code.user4581301
Do you have a .cpp file (just one) in the project that creates the precompiled header, rather than using it?Adrian Mole

1 Answers

0
votes

In my case, I had a corrupt cpp source file (a different one from where the error was occurring), caused by an earlier sudden power failure. It seems that once I recreated the corrupt file, the project was back into a valid state and the error went away the next time I built. ...It was a bit of a corner case, but you might clean/rebuild and check that nothing is corrupt.