I have a C++ console project that I included a precompiled header in the setup. I accidentally deleted the file from my project and now I can't compile because I get error C1083: Cannot open precompiled header file: 'Debug\Project.pch': No such file or directory
. Do I have to re-create the project and import all the code into it? I tried re-creating a file named "stdafx.cpp" that contains only #include "stdafx.h"
, but that does not work. How do I fix this?
Asked
Active
Viewed 1,120 times
0

einsteinsci
- 1,137
- 1
- 8
- 22
-
1Writing code without using source control is a Really Bad Idea. These accidents happen, source control is your fallback. – Hans Passant May 06 '14 at 18:25
-
Seems tangential, you wouldn't check machine-specific generated files (like pre-compiled headers) into source control. – nobody May 06 '14 at 19:05
-
@HansPassant This is just a minor project; I use Git for most of my projects. – einsteinsci May 06 '14 at 19:19
1 Answers
5
Right-click stdafx.cpp in Solution Explorer and choose Properties. Under C/C++ > Precompiled Headers, set "Precompiled Header" to "Create (/Yc)". You may also need to set "Precompiled Header File" to "stdafx.h" and "Precompiled Header Output File" to whatever makes sense ("$(IntDir)$(TargetName).pch" in most cases).
Unless there are other issues too, that should do it.

dlf
- 9,045
- 4
- 32
- 58
-
-
You're welcome. I spent quite a while trying to solve the same problem back in the day, and am happy to save someone else the trouble. – dlf May 06 '14 at 18:25