1
votes

I have Precompiled Headers enabled in a static library project I am working on. Looking around other StackOverflow questions, it seems like the key place to #include "stdafx.h" is in the .cpp file, not the .h file.

However, when I do this in Visual Studio, I get an IntelliSense error:

1 IntelliSense: PCH warning: header stop cannot be in a macro or #if block. An IntelliSense PCH file was not generated. ....\Common\Core\Geometry\Ellipsoid.h 9

The static library project does compile successfully, even with this IntelliSense error.

The .h file consists of this class declaration:

#ifndef GEOMETRY_ELLIPSOID_H
#define GEOMETRY_ELLIPSOID_H

class Ellipsoid { // 'class' is underlined with a red line (error)
    // ...
};

#endif // !GEOMETRY_ELLIPSOID_H

The .cpp defines the class declared in the header:

#include "Common\Core\stdafx.h"
#include "Ellipsoid.h"

// ...

By including stdafx.h in the header, the intelliSense error disappears. Is this the correct way to use precompiled headers? What implications are there in including stdafx.h in the header?

1
This isn't exactly the solution to your problem, but in Visual Studio I go to project properties -> C/C++ -> Advanced and put my PCH as a force include, and then never worry about it again!Neil Kirk

1 Answers

-1
votes

You have to add #pragma once at the start of the file Answere is here: PCH Warning: header stop cannot be in a macro or #if block - Visual C++ 2010 Express SP1 macro-or-if-block-visual-c-2010-exp