PCH 警告:标题停止不能在宏或 #if 块中 - Visual C++ 2010 Express SP1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6003603/
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
PCH Warning: header stop cannot be in a macro or #if block - Visual C++ 2010 Express SP1
提问by pighead10
This is pasted from a website, which presumably was working. I did some googling and found that the issue I have now is a result of Visual C++ 2010 SP1, which I downloaded today, and is now giving me this error:
这是从一个网站粘贴过来的,该网站可能正在运行。我做了一些谷歌搜索,发现我现在遇到的问题是我今天下载的 Visual C++ 2010 SP1 的结果,现在给了我这个错误:
PCH Warning: header stop cannot be in a macro or #if block.
PCH Warning: header stop cannot be in a macro or #if block.
Hopefully someone will be able to help me with this!
希望有人能够帮助我解决这个问题!
#ifndef APP_STATE_H
#define APP_STATE_H
#include "Framework.h"
class AppState; //this line is giving me the error
//define two classes
#endif
Framework.h:
框架.h:
#ifndef OGRE_FRAMEWORK_H
#define OGRE_FRAMEWORK_H
#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreOverlay.h>
#include <OgreOverlayElement.h>
#include <OgreOverlayManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>
#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>
class OgreFramework : public Ogre::Singleton<OgreFramework>,OIS::KeyListener,OIS::MouseListener{
public:
OgreFramework();
~OgreFramework();
bool initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener = 0, OIS::MouseListener *pMouseListener = 0);
void updateOgre(double timeSinceLastFrame);
//OIS
bool keyPressed(const OIS::KeyEvent &keyEventRef);
bool keyReleased(const OIS::KeyEvent &keyEventRef);
bool mouseMoved(const OIS::MouseEvent &evt);
bool mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id);
Ogre::Root* mRoot;
Ogre::RenderWindow* mRenderWnd;
Ogre::Viewport* mViewport;
Ogre::Log* mLog;
Ogre::Timer* mTimer;
//OIS
OIS::InputManager* mInputMgr;
OIS::Keyboard* mKeyboard;
OIS::Mouse* mMouse;
private:
OgreFramework(const OgreFramework&);
OgreFramework& operator= (const OgreFramework&);
};
#endif
回答by Kash
I had the same issue and was looking for a solution. Following worked for me:
我遇到了同样的问题,正在寻找解决方案。以下为我工作:
Add #pragma once
at the start of the file (even before the #ifndef APP_STATE_H
header guard)
添加#pragma once
在文件的开头(甚至在#ifndef APP_STATE_H
标题保护之前)
回答by Hans Passant
You probably used a project template to get started and threw away the pre-generated source code files. Those project templates like to turn on precompiled headers because it is such a time-saver. Right-click your project in the Solution Explorer window, Properties, C/C++, Precompiled Headers. Change the "Precompiled Header" setting to "Not Using".
您可能使用了一个项目模板开始并丢弃了预先生成的源代码文件。那些项目模板喜欢打开预编译头,因为这样可以节省时间。在解决方案资源管理器窗口中右键单击您的项目、属性、C/C++、预编译头文件。将“预编译头”设置更改为“不使用”。
回答by One Double
1.Close the Project. 2.Reopen the project,and all ok. this is my expeirence.
1.关闭项目。2.重新打开项目,一切OK。这是我的经验。
回答by Nour
move the #include statements outside the #if #end block
将 #include 语句移到 #if #end 块之外
回答by Fabian
I had the same problem. My solution was to add a missing ';' at the end of a class definition. Although this does not seem to apply to your problem, others who come here with the same error might find this helpful.
我有同样的问题。我的解决方案是添加一个缺失的 ';' 在类定义的末尾。尽管这似乎不适用于您的问题,但其他遇到相同错误的人可能会发现这很有帮助。
回答by vahapt
Rebuilding IntelliSense database solves the problem.
重建 IntelliSense 数据库解决了这个问题。
- Close Visual Studio
- Delete [SolutionName].sdf
- Delete DllWrappers.opensdf
- Delete ipchfolder
- Open Visual Studio
- 关闭 Visual Studio
- 删除[解决方案名称].sdf
- 删除DllWrappers.opensdf
- 删除ipch文件夹
- 打开 Visual Studio
回答by AndyG
I found that my .h file was actually being treated as a .cpp file! Right click on the file in the Solution Explorer > All Configurations > Item Type: C/C++ header
我发现我的 .h 文件实际上被视为 .cpp 文件!右键单击解决方案资源管理器中的文件 > 所有配置 > 项目类型:C/C++ 标头
Make sure the item type is not C/C++ compiler or other.
确保项目类型不是 C/C++ 编译器或其他类型。
回答by doug
This is probable a day late and a dollar short but I had the same error when I accidentally put my header file in a .cpp file instead of a .h file. I will post it though in case it can help someone.
这可能是晚了一天和一美元的空头,但是当我不小心将头文件放在 .cpp 文件而不是 .h 文件中时,我遇到了同样的错误。我会发布它,以防万一它可以帮助某人。
回答by Ilan
I just added a referenct to the header file (#include "header.h") and it helped.
我刚刚向头文件(#include“header.h”)添加了一个引用,它有帮助。
回答by codyj110
Once you add a .cpp file and have it include the header this error should go away. I've read some where else this is a bug.
一旦你添加了一个 .cpp 文件并让它包含标题,这个错误就会消失。我读过一些其他地方这是一个错误。