10

This worked without error when this solution worked off of .lib files instead of .dll files.

I have all of my projects except one currently using a precompiled header, without error. The precompiled header is called "LudoGlobal.h". I am trying to link the last project to this precompiled header (which exists in a seperate, "Core", project) but I'm getting the following error:

Error 4 fatal error C1083: Cannot open precompiled header file: '....\Output\LudoSound\Debug\LudoSound.pch': No such file or directory ludosoundmanager.cpp 1

for each .cpp file. Why is this? How can I solve it?

I realize LudoSound.pch does not exist. I am under the assumption that it probably gets created when LudoSound compiles, yesno?

  • Check if file (....\Output\LudoSound\Debug\LudoSound.pch') exist. – lsalamon Oct 15 '09 at 18:24
  • It doesn't. It would need to be built, I'm assuming. This appears to be stopping it. –  Oct 15 '09 at 18:26
  • Possible duplicate of [How to fix .pch file missing on build?](https://stackoverflow.com/questions/6096384/how-to-fix-pch-file-missing-on-build) – user276648 Oct 11 '18 at 05:39

4 Answers4

25

Are you using "automatically generate", or "use precompiled header" on the project and "create precompiled header" on the one cpp file? The latter is more efficient, but I've seen the per-file configuration on projects get accidentally reset, so that the "stdafx.cpp" (or whatever) file no longer generates the precompiled header.

Tim Sylvester
  • 22,897
  • 2
  • 80
  • 94
  • 1
    I'm using Use PrecompiledHeader (/Yu). with Create/Use PCH Through File Ludocore\LudoGlobal.h. LudoGlobal is my precompiled header –  Oct 15 '09 at 18:32
  • You need to have one cpp file (LudoGlobal.cpp) that includes the .h file and has the proper configuration settings different from all the other .cpp files. – Mark Ransom Oct 15 '09 at 18:41
  • I have the one .cpp file, but what configuration settings are you speaking of? Note that this is workign as a precompiled header for several other projects.. –  Oct 15 '09 at 18:44
  • 6
    You need to go to "properties" for that one .cpp file (as opposed to the project properties) and set it to "Create Precompiled Header". – Tim Sylvester Oct 15 '09 at 19:15
  • 1
    So the `LudoGlobal.cpp` file is set to "Create Precompiled Header", but when you compile that cpp file, no pch file is generated *and* no errors occur? Maybe the intermediate/output directories (or the pch file location) don't match so the other files are looking for it in a different place than it's generated in. When you rebuild the project, does it always build `LudoGlobal.cpp` first? Can you post the .vcproj file? – Tim Sylvester Oct 15 '09 at 19:33
  • 1
    I've got the same odd problem, having dozens of same errors like '{}"' character badly placed, but everything compiled fine earlier. This makes me want to slap a microsoft employee, seriously. – jokoon Dec 19 '10 at 12:09
  • I have the same problem as topic starter, I have two projects inside one solution and I want one project to generate PCH and other project to reuse it. If I compile the first (master) project alone, it generates PCH without any issues. But when I'm trying to compile the second project (dependencies, additional incude directory, path to PCH are all set) it just removed .PCH file from the master project and exits with error "Cannot open precompiled header file" – The Godfather Sep 21 '15 at 10:08
4

I had this issue after I deleted and re-added stdafx.cpp from & to my project. Solution:

  • stdafx.cpp needs to have the property Create PrecompiledHeader (/Yc), this sets stdafx.cpp as the one that is responsible for creating the .pch from stdafx.h
  • the project (and with that all the files in it) can have the property Use PrecompiledHeader (/Yu), they can use .pch created by the compilation of stdafx.cpp
Remco Boom
  • 131
  • 2
0

LudoSound.pch was not regenerated. Delete only the folder it was in and build again.

apollo
  • 1
0

Try rebuilding your project in a new, copying only the files needed supplies.

lsalamon
  • 7,998
  • 6
  • 50
  • 63