在Windows上使用clang编译c ++ 11程序时出错

时间:2012-10-29 13:20:37

标签: c++ windows visual-c++ c++11 clang

我在Windows上构建了clang 3.2并且正在尝试构建一个简单的hello world程序。但是我得到了很多错误,如下所示。

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代码?我是否必须提供额外的命令切换?

2 个答案:

答案 0 :(得分:3)

由Visual Studio构建时,Clang无法正常工作(据说MinGW构建时可以正常工作,但我无法自行验证)。

构建Clang时,它被配置为使用用于构建它的库。由于您使用Visual Studio构建了Clang,因此Clang将尝试使用Visual Studio头文件和库。不幸的是,Clang和Visual Studio的内部结构不同,Clang 无法使用VS特定的标题。

在为Windows编译libc++之前,Clang将(几乎肯定)在Visual Studio编译时不会工作。尝试使用MinGW构建它(并制作博客文章或者你如何做到这一点!),看看它是否适合你。

答案 1 :(得分:0)

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

在构建期间还单独编译和链接阶段。这将导致链接使用正确的二进制库而不是VS默认值。

相关问题