开发者

What causes "error C2856: #pragma hdrstop cannot be inside an #if block" in VS C++?

There was a program what I could compile under 2008 for a while. Note I can compile the program using cl and in Ultimate++ IDE. It is a fairly large program , so I am not going to post it here. I cannot compile it in Studio.

The error is

1>c:\program files\microsoft visual studio 9.0\vc\include\xstring(1735)
: error C2856: #pragma hdrstop cannot be inside an #if block

which seems to be idiotic as there is no hdrstop in there.

Precompiled headers are turned off.

This is what is there:

            if (_Mysize < _Off)
                _String_base::_Xran();  // _Off off end
            if (_Mysize - _Off < _Count)
                _Count = _Mysize - _Off;
            _Traits_helper::copy_s<_Traits>(_Dest, _Dest_size, _Myptr() + _Off, _Count);
            return (_Co开发者_运维百科unt);
            }

        void __CLR_OR_THIS_CALL swap(_Myt& _Right)
            {   // exchange contents with _Right <<<<<<<<----------this is the line 
            if (this == &_Right)
                ;   // same object, do nothing
            else if (_Mybase::_Alval == _Right._Alval)
                {   // same allocator, swap control information

Thanks.


I found this out. It caused by precompiled headers, yes but there is no need to turn this off.

It happens when a top level #include "headertobeprecompiled.h" is inside an #if #endif block. If one can move it outside that the error message disappears.


Wild guess.

The precompiled headers are switched off for the project? Are they switched off for every single source file in the project (cause individual file settings overwrite whole-project settings).


Because Visual C++ invokes cl (which works fine) and you obviously have messed up headers, the first thing I'd check are include paths. Post them here.


I have experienced the exact same problem and was also puzzled since I don't have any hdrstop pragmas in my code, either. However, I compile from a script (not an IDE) and when I omit the compiler option /Yc (create PCH) the error disappears.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜