在VS C ++中导致“错误C2856:#pragma hdrstop不能在#if块中”的原因是什么?

时间:2010-02-26 13:48:49

标签: visual-c++ visual-c++-2008-express

有一个程序,我可以在2008年编译一段时间。 注意我可以使用cl和Ultimate ++ IDE编译程序。 这是一个相当大的程序,所以我不打算在这里发布。 我无法在Studio中编译它。

错误是

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

这似乎是愚蠢的,因为那里没有hdrstop。

预编译的标题已关闭。

这就是:

            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 (_Count);
            }

        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

感谢。

4 个答案:

答案 0 :(得分:3)

疯狂猜测。

项目的预编译头是否已关闭?它们是否针对项目中的每个源文件关闭(导致单个文件设置覆盖整个项目设置)。

答案 1 :(得分:3)

我发现了这一点。它是由预编译头引起的,是的,但没有必要关闭它。

顶级#include "headertobeprecompiled.h"位于#if #endif区块内时会发生这种情况。如果可以将其移到外面,则错误消息将消失。

答案 2 :(得分:0)

因为Visual C ++调用cl(工作正常)而你显然搞乱了标题,所以我要检查的第一件事就是包含路径。将它们发布在这里。

答案 3 :(得分:0)

我遇到了完全相同的问题并且也很困惑,因为我的代码中也没有任何hdrstop pragma。但是,我从脚本(而不是IDE)编译,当我省略编译器选项/ Yc(创建PCH)时,错误消失。