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?
Asked
Active
Viewed 932 times
0

voxoid
- 1,164
- 1
- 14
- 31
-
1Have you added `#pragma once` (include guard) on top of the header file? – NutCracker Oct 16 '19 at 22:05
-
Yes, thanks, I should have mentioned that before; edited. – voxoid Oct 16 '19 at 22:06
-
Have you tried [this](https://stackoverflow.com/a/32588641/5517378). – NutCracker Oct 16 '19 at 22:06
-
2I 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 [mcve] doesn't show you what the problem is, post the resulting code. – user4581301 Oct 16 '19 at 22:06
-
The precompiled header file name can be configured for each source file. The default used to be `stdafx.h`. – Mark Ransom Oct 16 '19 at 22:11
-
1Do you have a .cpp file (just one) in the project that *creates* the precompiled header, rather than *using* it? – Adrian Mole Oct 16 '19 at 22:13
-
@Adrian yes, pch.cpp is there. – voxoid Oct 16 '19 at 22:35
-
@Mark Ransom the default in the project template I used was pch.h; maybe this is an update. – voxoid Oct 16 '19 at 22:35
-
@NutCracker I do prefer pre-compiled headers though, rather than disabling them. – voxoid Oct 16 '19 at 22:35
1 Answers
0
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.

voxoid
- 1,164
- 1
- 14
- 31