PCH警告:头文件停止不能位于macros或#if块中 – Visual C ++ 2010 Express SP1

这是从一个网站粘贴,这大概是工作。 我做了一些Googlesearch,发现我现在遇到的问题是今天下载的Visual C ++ 2010 SP1的结果,现在给我这个错误:

PCH Warning: header stop cannot be in a macro or #if block.

希望有人能帮助我这个!

 #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:

 #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 

我有同样的问题,正在寻找一个解决scheme。 以下为我工作:

在文件开头添加#pragma once (甚至在#ifndef APP_STATE_H头文件之前)

您可能使用了一个项目模板来开始并丢弃预生成的源代码文件。 这些项目模板喜欢打开预编译头,因为这是一个节省时间。 在“解决scheme资源pipe理器”窗口的“属性”,“C / C ++”,“预编译头”中右键单击项目。 将“预编译的标题”设置更改为“不使用”。

移动#if#结尾块之外的#include语句

重buildIntelliSense数据库解决了这个问题。

  1. closuresVisual Studio
  2. 删除[SolutionName] .sdf
  3. 删除DllWrappers.opensdf
  4. 删除ipch文件夹
  5. 打开Visual Studio

这是可能的一天晚和一美元短,但我有同样的错误,当我不小心把我的头文件在.cpp文件而不是.h文件。 我会尽快发布,以防万一它可以帮助某人。

我只是添加引用文件头文件(#包括“header.h”),它有帮助。

我发现我的.h文件实际上被视为一个.cpp文件! 在“解决scheme资源pipe理器”>“所有configuration”>“项目types:C / C ++头”中右键单击该文件

确保项目types不是C / C ++编译器或其他。

1.closures项目。 重新打开项目,一切正常。 这是我的宽容。

我有同样的问题。 我的解决办法是添加一个失踪的';' 在类定义的末尾。 虽然这似乎并不适用于您的问题,但其他同样出现在这里的人可能会觉得这很有帮助。

一旦你添加一个.cpp文件,并让它包含标题,这个错误应该消失。 我已经读了一些其他地方这是一个错误。

当我这样做时,这发生在我身上:

文件啊:

 #include "bh" . . . 

文件bh:

 #include "ah" . . .