C++ 查找预编译头文件时跳过
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2945980/
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
skipped when looking for precompiled header
提问by numerical25
So some reason, my .cpp file is missing it's header file. But I am not including the header file anywhere else. I just started so I checked all the files I made
所以出于某种原因,我的 .cpp 文件丢失了它的头文件。但我没有在其他任何地方包含头文件。我刚开始,所以我检查了我制作的所有文件
enginuity.h
机智.h
#ifndef _ENGINE_
#define _ENGINE_
class Enginuity
{
public:
void InitWindow();
};
enginuity.cpp
工程.cpp
#include "Enginuity.h"
void Enginuity::InitWindow()
{
}
main.cpp
主程序
#include "stdafx.h"
#include "GameProject1.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
code.....
#endif
dont know what's going on. The error I get is
不知道怎么回事。我得到的错误是
1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(1) : warning C4627: '#include "Enginuity.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
回答by Billy ONeal
Did you read the error message?
您是否阅读了错误消息?
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
致命错误 C1010:查找预编译头时文件意外结束。您是否忘记将“#include“stdafx.h””添加到您的源代码中?
I don't see an #include "stdafx.h"
in enginuity.cpp. ;) If you're using precompiled headers, you need to include the precompiled header in everysource (.cpp) file.
我#include "stdafx.h"
在 enginuity.cpp 中没有看到。;) 如果您使用预编译头文件,则需要在每个源 (.cpp) 文件中包含预编译头文件。
回答by Gordon Glas
I just experienced this error when including stdafx.h in a cpp file located in a parent folder above where stdafx.h is.
我刚刚在将 stdafx.h 包含在位于 stdafx.h 所在父文件夹中的 cpp 文件中时遇到了这个错误。
#include "subfolder\stdafx.h"
causes the compile error. Changing it to:
导致编译错误。将其更改为:
#include "stdafx.h"
fixes the compile error, but then intellisense freaks out.
修复了编译错误,但随后智能感知吓坏了。
The "fix" for intellisense, according to someone at Microsoft here, is to add "$(ProjectDir)" (or wherever the stdafx.h is) to the list of directories under Project->Properties->Configuration Propertes->C/C++->General->Additional Include Directories.
根据微软这里的某人的说法,intellisense 的“修复”是将“$(ProjectDir)”(或 stdafx.h 所在的任何位置)添加到 Project->Properties->Configuration Propertes->C/ 下的目录列表中C++->常规->附加包含目录。
I've verified this works in Visual Studio 2012. Should work in 2010 as well.
我已经验证这在 Visual Studio 2012 中有效。在 2010 中也应该有效。
回答by JohnMcG
You'll either want to put the line
你要么想把这条线
#include "stdafx.h"
at the top of all your .cpp files (in this case, enenuity.cpp is the only one missing it.
在所有 .cpp 文件的顶部(在这种情况下, enenuity.cpp 是唯一缺少它的文件。
or disable precompiled headers in your project.
或禁用项目中的预编译头文件。
If you have precompiled headers enabled in your project, Visual C++ will look for that #include
directive at the top of all your source files. If it's not there, you'll get the negative commentary you received.
如果在项目中启用了预编译头,Visual C++ 将#include
在所有源文件的顶部查找该指令。如果它不在那里,你会得到你收到的负面评论。
回答by Viktor
IF APPROVED SOLUTION DOES NOT WORK FOR YOU:
如果批准的解决方案对您不起作用:
In my case the stdafx.h include was after other includes in my .cpp file.
就我而言,stdafx.h 包含在我的 .cpp 文件中的其他包含之后。
Setting the #include "stdafx.h" statement at the TOP of the .cpp file fixed my errors.
在 .cpp 文件的顶部设置 #include "stdafx.h" 语句修复了我的错误。
回答by user1577802
It is possible to disable precompiled headers for a single file (VS2010). Select the .cc or .cpp file that is causing the annoyance, right mouse menu, properties, precompiled headers , Precompiled Header (change to) Not Using Precompiled Headers.
可以禁用单个文件的预编译头 (VS2010)。选择引起烦恼的 .cc 或 .cpp 文件、鼠标右键菜单、属性、预编译头、预编译头(更改为)不使用预编译头。
回答by Thomas Matthews
Your header file, enginuity.h
is missing a #endif
, or is there a mistake in the posting?
您的头文件,enginuity.h
缺少一个#endif
,还是发布中有错误?
回答by wonderlr
Instead of adding #include "stdafx.h" to each .cpp file, you can use the Forced Include File feature. The feature is documented here: https://msdn.microsoft.com/en-us/library/8c5ztk84.aspx.
您可以使用强制包含文件功能,而不是将 #include "stdafx.h" 添加到每个 .cpp 文件中。该功能记录在此处:https: //msdn.microsoft.com/en-us/library/8c5ztk84.aspx。
In my case, I was trying to compile existing .cpp files from another project in a new project. I knew that I shouldn't have to change each file because the original project had precompiled headers enabled and it was somehow compiling the same files successfully. I discovered that this option was configured in the original project, and the error went away after I made the same configuration in the new project.
就我而言,我试图从新项目中的另一个项目编译现有的 .cpp 文件。我知道我不应该更改每个文件,因为原始项目启用了预编译头,并且它以某种方式成功编译了相同的文件。发现原来的项目中配置了这个选项,在新项目中做同样的配置后错误就消失了。
回答by HaltingState
This error will occur if you have two solutions in a subdirectory of a project and precompiled headers are enabled. I have experienced the same problem and Microsoft has not fixed it yet.
如果您在项目的子目录中有两个解决方案并且启用了预编译头,则会出现此错误。我遇到了同样的问题,微软还没有修复它。
https://connect.microsoft.com/VisualStudio/feedback/details/552449/
https://connect.microsoft.com/VisualStudio/feedback/details/552449/
The microsoft work around sometimes works.
微软的工作有时会奏效。
回答by George
Add #include "stdafx.h" to the top of enginuity.cpp or disable precompiled headers in your project.
将 #include "stdafx.h" 添加到 enginuity.cpp 的顶部或禁用项目中的预编译头文件。
回答by Michael J.
As Viktor noted above including stdafx.h afterother includes will also cause this error and can happen quite easily if you use the Add Function Wizard. In my case, the wizard added the #include to the trop of the cpp file (despite that it was already included) so I ended up with (using this example)
正如 Viktor 上面提到的,在其他包含之后包含 stdafx.h也会导致此错误,如果您使用添加函数向导,很容易发生。在我的情况下,向导将 #include 添加到 cpp 文件的 trop (尽管它已经包含在内)所以我结束了(使用这个例子)
#include "Enginuity.h"
#include "stdafx.h"
// ... other includes ...
#include "Enginuity.h"