【问题标题】:Error building legacy code with VS 2005使用 VS 2005 构建遗留​​代码时出错
【发布时间】:2010-08-26 07:38:56
【问题描述】:

尝试在 VS2005 中构建遗留代码并在 VC 头文件中出错。

d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2065: '_Sb' : undeclared identifier
    d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C3861: '_Strbuf': identifier not found
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2061: syntax error : identifier '_Sb'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2097) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2143: syntax error : missing ';' before '{'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : fatal error C1075: end of file found before the left brace '{' at 'd:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(15)' was matched

我发现遗留代码使用向量,如果我注释掉这些变量,那么代码编译时不会出现任何错误。 即使我只包含矢量头而不定义任何变量,我也会收到这些错误。

项目中的所有文件都是cpp文件。

我是否需要添加一些预处理器指令或编译器设置才能使其正常工作?

【问题讨论】:

    标签: c++ visual-c++


    【解决方案1】:

    您可能会发现,在其中一个文件上运行预处理阶段可能会显示是否有任何宏正在扩展,与vector_Strbuf 冲突。请参阅我的帖子以了解如何执行此操作:

    Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

    【讨论】:

    • 谢谢。我预处理了编译失败的文件,但在 .i 文件中没有看到 vector_Strbuf 的任何冲突定义
    • 现在您有了 .i 文件,尝试注释掉其中的区域以隔离它所抱怨的代码(即进行二进制搜索)。
    【解决方案2】:

    您可能需要删除一些冲突的预定义宏。前导下划线后跟大写字母,如_Sb,保留用于实现。如果您将其定义为其他内容,则会出现此类错误。错误也可能是因为您定义了_Strbuf ot _Got

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多