C++ 带有 DLL 解决方案的预编译头文件。无法打开预编译头文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1574121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Precompiled headers with DLL solutions. Cannot open precompiled header file
提问by Tim Sylvester
This worked without error when this solution worked off of .lib files instead of .dll files.
当此解决方案使用 .lib 文件而不是 .dll 文件时,这没有错误。
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:
我有我的所有项目,除了一个当前使用预编译头的项目,没有错误。预编译头文件称为“ LudoGlobal.h”。我试图将最后一个项目链接到这个预编译的头文件(它存在于一个单独的“核心”项目中),但我收到以下错误:
Error 4 fatal error C1083: Cannot open precompiled header file: '....\Output\LudoSound\Debug\LudoSound.pch': No such file or directory ludosoundmanager.cpp 1
错误 4 致命错误 C1083:无法打开预编译头文件:'....\Output\LudoSound\Debug\LudoSound.pch':没有这样的文件或目录 ludosoundmanager.cpp 1
for each .cpp file. Why is this? How can I solve it?
对于每个 .cpp 文件。为什么是这样?我该如何解决?
I realize LudoSound.pch does not exist. I am under the assumption that it probably gets created when LudoSound compiles, yesno?
我意识到 LudoSound.pch 不存在。我假设它可能是在 LudoSound 编译时创建的,是吗?
回答by Tim Sylvester
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.
您是在项目上使用“自动生成”还是“使用预编译头”,并在一个 cpp 文件上使用“创建预编译头”?后者效率更高,但我已经看到项目上的每个文件配置被意外重置,因此“stdafx.cpp”(或其他)文件不再生成预编译头文件。
回答by Remco Boom
I had this issue after I deleted and re-added stdafx.cpp from & to my project. Solution:
在我从 & 删除并重新添加 stdafx.cpp 到我的项目后,我遇到了这个问题。解决方案:
- 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
- stdafx.cpp 需要具有属性 Create PrecompiledHeader (/Yc),这将 stdafx.cpp 设置为负责从 stdafx.h 创建 .pch 的那个
- 该项目(以及其中的所有文件)可以具有 Use PrecompiledHeader (/Yu) 属性,它们可以使用由 stdafx.cpp 编译创建的 .pch
回答by lsalamon
Try rebuilding your project in a new, copying only the files needed supplies.
尝试在新的项目中重建您的项目,仅复制所需的文件。
回答by apollo
LudoSound.pch was not regenerated. Delete only the folder it was in and build again.
LudoSound.pch 未重新生成。只删除它所在的文件夹并重新构建。