Home » C++ » PCH Warning: header stop cannot be in a macro or #if block – Visual C++ 2010 Express SP1

PCH Warning: header stop cannot be in a macro or #if block – Visual C++ 2010 Express SP1

Posted by: admin November 29, 2017 Leave a comment

Questions:

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:

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:

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

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)

Questions:
Answers:

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”.

Questions:
Answers:

move the #include statements outside the #if #end block

Questions:
Answers:

Rebuilding IntelliSense database solves the problem.

  1. Close Visual Studio
  2. Delete [SolutionName].sdf
  3. Delete DllWrappers.opensdf
  4. Delete ipch folder
  5. Open Visual Studio
Questions:
Answers:

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.

Questions:
Answers:

I just added a referenct to the header file (#include “header.h”) and it helped.

Questions:
Answers:

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

Make sure the item type is not C/C++ compiler or other.

Questions:
Answers:

1.Close the Project.
2.Reopen the project,and all ok.
this is my expeirence.

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

this happen to me when I do this :

file a.h :

#include "b.h"
.
.
.

file b.h :

#include "a.h"
.
.
.