C++ 编译c+时出错+;11在windows上发出叮当声的程序

C++ 编译c+时出错+;11在windows上发出叮当声的程序,c++,windows,visual-c++,c++11,clang,C++,Windows,Visual C++,C++11,Clang,我在windows上构建了Clang3.2,并试图构建一个简单的HelloWorld程序。但是我得到了很多错误,就像下面看到的一样 d:\Marius\xyz>clang++ -stdlib=libc++ -std=c++11 -Wall xyz.cpp -o xyz.exe clang++: warning: argument unused during compilation: '-stdlib=libc++' In file included from xyz.cpp:12: In

我在windows上构建了Clang3.2,并试图构建一个简单的HelloWorld程序。但是我得到了很多错误,就像下面看到的一样

d:\Marius\xyz>clang++ -stdlib=libc++ -std=c++11 -Wall xyz.cpp -o xyz.exe
clang++: warning: argument unused during compilation: '-stdlib=libc++'
In file included from xyz.cpp:12:
In file included from ./stdafx.h:18:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\algorithm:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory0:9:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility:8:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\utility:8:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\type_traits:1072:
33: error:
  '_Ty' does not refer to a value
            _HAS_TRIVIAL_MOVE_CONSTRUCTOR(_Ty)
                                          ^

...

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef:540:50: note:
      expanded from macro '_VARIADIC_EXPAND_4'
#define _VARIADIC_EXPAND_4(FUNC, X1, X2, X3, X4) \
                                                 ^
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xrefwrap:222:22:note:
      expanded from macro '_CLASS_RESULT_OF_PMF_OPT_0X'
                        __thiscall, X2, X3, X4)
                                          ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

我从VC++2012标题中得到了很多类似的错误。是否有可能在Windows上使用clang++构建C++11代码?我必须提供额外的命令开关吗?

当由Visual Studio构建时,Clang无法正常工作(假定它在由MinGW构建时工作,但我自己还无法验证这一点)

构建Clang时,它被配置为使用用于构建它的库。由于您使用VisualStudio构建了Clang,Clang将尝试使用VisualStudio头和库。不幸的是,Clang和visualstudio的内部差别很大,以至于Clang不能使用VS特定的头文件


在可以为Windows编译之前,Clang(几乎可以肯定)在VisualStudio编译时永远不会工作。试着用MinGW构建它(并写一篇博客或其他关于你是如何做到这一点的东西!),看看这是否适合你。

clang默认为用于构建它的工具链的包含部分。但与MS一样,使用的扩展可能是特定于供应商的。clang自己的libc++可用性有望大大缓解这个问题。手动指定正确的包含目录


在构建过程中,还要分离编译和链接阶段。这将导致链接使用比VS默认值更正确的二进制LIB。

-fms extensions
可能。根据用户手册(),默认情况下启用该标志。我还尝试设置-fmsc version=1700(即VS2012)甚至-fdelayed模板解析(这也是默认设置)。没有结果。删除stdafx.h对编译错误没有影响。我还尝试将mingw头与-isystem一起使用,但这看起来像一场配置噩梦。根据包含的顺序,我会遇到不同的错误,并且在没有编译错误的情况下无法设置顺序。@Mat关于stdafx.h,Microsoft没有任何特定的内容。这是一个完全符合标准的项目特定文件。如果启用某些选项,VisualStudio编译器只会缓存已编译的输出。