std库中的Visual Studio编译错误

Posted

技术标签:

【中文标题】std库中的Visual Studio编译错误【英文标题】:Visual Studio Compile errors in std library 【发布时间】:2015-07-17 21:16:34 【问题描述】:

我正在尝试按照此处提供的说明在 Visual Studio 2015 RC 中松散地构建 Facebook 愚蠢: https://github.com/jbandela/folly/tree/vc11

我希望通过 2015 年扩展的 C++11 支持,我可能会比以前更轻松。我一直在以一个不错的剪辑解决问题,但我目前遇到了一组对我来说没有意义的编译错误。这是第一个错误的编译输出的顶部:

2>------ Build started: Project: folly, Configuration: Debug Win32 ------
2>  pch.cpp
2>  Unknown compiler version - please run the configure tests and report the results
2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(26): error C2143: syntax error: missing ',' before '<'
2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(26): error C2143: syntax error: missing ',' before '<'

这是它带给我的错误位置的来源,再次在 std 命名空间的 xstring 中:

template<class _Mystr>
class _String_const_iterator
    : public _Iterator012<random_access_iterator_tag, // <---- line 26
        typename _Mystr::value_type,
        typename _Mystr::difference_type,
        typename _Mystr::const_pointer,
        typename _Mystr::const_reference,
        _Iterator_base>

我遇到的另一个错误示例:

 C2039  'exception': is not a member of 'std'   folly   c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdexcept    27

来源:

class logic_error
    : public _XSTD exception
       

我很困惑这些和其他 219 错误是如何与 std 库本身相关的。我通常从 Linux/g++ 构建,所以我不熟悉 Visual Studio 构建环境。我可能做一些简单的错误。出现此类错误的原因可能是什么?


更新 1

添加更多信息。我在没有提升的情况下复制了这个,所以“未知的编译器版本”警告消失了。我还从编译中获得了更多输出:

     Microsoft (R) C/C++ Optimizing Compiler Version 19.00.22816 for x86
     Copyright (C) Microsoft Corporation.  All rights reserved.

     cl /c /I"C:\Users\myname\Documents\Visual Studio 2015\Projects\folly\folly\folly\folly" /I"C:\Users\myname\Documents\Visual Studio 2015\Projects\folly\folly\\" /I"Generated Files\\" /IDebug\ /ZI /ZW /ZW:nostdlib /W3 /WX- /sdl /MP /Od /Oy- /D _VARIADIC_MAX=10 /D FOLLY_NO_CONFIG /D _TIMESPEC_DEFINED /D FOLLY_HAVE_STD__IS_TRIVIALLY_COPYABLE /D _UNICODE /D UNICODE /D _DEBUG /D WINAPI_FAMILY=WINAPI_FAMILY_APP /D __WRL_NO_DEFAULT_LIB__ /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Yc"pch.h" /Fp"Debug\folly.pch" /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /wd4453 /wd28204 /FU"C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.VCLibs\14.0\References\CommonConfiguration\neutral\platform.winmd" /FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0\Windows.Foundation.FoundationContract.winmd" /FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd" /FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Networking.Connectivity.WwanContract\1.0.0.0\Windows.Networking.Connectivity.WwanContract.winmd" /analyze- /errorReport:prompt /bigobj pch.cpp

     pch.cpp
 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(26): error C2143: syntax error: missing ',' before '<'
     c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(266): note: see reference to class template instantiation 'std::_String_const_iterator<_Mystr>' being compiled
 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(27): error C2518: keyword 'typename' illegal in base class list; ignored
 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(28): error C2518: keyword 'typename' illegal in base class list; ignored
 1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring(29): error C2518: keyword 'typename' illegal in base class list; ignored
 ...

更新 2

无论是否启用预编译头选项,都会发生这些错误。

【问题讨论】:

在构建输出中,我注意到错误消息“未知编译器版本...”。你能检查你的头文件是什么条件触发了这个消息吗? 感谢您的评论。关于编译器版本的消息来自 boost。我在网上读到这是无害的,但我在项目中重新设计了一些东西,所以它目前没有用 boost 编译来消除这个信息。在水平线下方查看我的更新。现在该注释消失了,但我仍然收到错误消息。 您的目标是什么 Windows 版本?您可以尝试将“/D WIN32_WINNT=0x0601”添加到您的命令行以针对 Windows 7 吗?详情请见msdn。 此时,我只是想让它编译。任何目标都可以。我添加了“/D WIN32_WINNT=0x0601”,但仍然出现同样的错误。 您能否尝试使用预编译的头文件创建一个全新的 Visual C++ Win32 项目,同时确保 stdafx.h 或 pch.h 最终导入 xstring.h?让我们看看它是否正确构建...... 【参考方案1】:

这条消息:

未知的编译器版本 - 请运行配置测试并报告 结果

由 boost 头文件之一发出。 Boost 需要特定版本的 VC++,在本例中为 11.0,对应于 VS 2012。这可能是您收到所有这些错误的原因。您必须下载 Visual Studio 2012,然后按照您提到的链接中的说明进行操作。

【讨论】:

如帖子中所述(请参阅更新 1),即使从图片中删除提升后,我也会收到这些 std 错误。 @firebush 我知道。尽管如此,还是需要 VS 2012 才能成功编译代码。【参考方案2】:

您是否确保标头 dll 是最新的?它们经常更新。 我在具有相同构建的多个系统上运行时遇到过这种情况。 另一项检查是在库调用的开头添加 std:: ,以确保 - 这样您就可以轻松测试天气它是 dll 还是您的拼写。

另外请检查您是否收到“v120”或“v140”工具集错误,这表明您是否错误地使用了 VS 版本。

另一种方法是将 VC lib 文件作为本地“头文件”包含在内,至少确保编译器连接。

希望对你有帮助

【讨论】:

以上是关于std库中的Visual Studio编译错误的主要内容,如果未能解决你的问题,请参考以下文章

websocketpp库中的错误和Windows Visual Studio 2015中的提升[关闭]

GCC-Visual Studio std::thread 编译器差异

Visual Studio 2015不会禁止错误C4996

错误 C1083:如何修复损坏的 Visual Studio 编译器?

Visual Studio 2015 不会抑制错误 C4996

Visual Studio中的c ++编译器标志