5

根据http://clang.llvm.org/get_started.html ,我使用 Visual Studio 2010 在 Windows 上进行了 ALL_BUILD,并使用 $PATH=...ClangSourcBuildPath...\build\bin\ 将构建的东西添加到我的系统路径中发布

我现在可以在控制台上编译以下文件:

$> 铿锵文件_c.c

//file_c.c
#include <stdio.h>

int main() 
{
  printf("hello world\n");
  return 0;
}

但是如果我对以下文件($> clang file_cpp.cpp)做同样的事情:

//file_cpp.cpp
#include <iostream>

int main()
{
    std::cout << "Hello World!";
    return 0;
}

我收到以下错误:

在 file_cpp.cpp:1 中包含的文件中:

In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\iostream:9:   
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\istream:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\ostream:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\ios:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\streambuf:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xlocnum:13:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xiosbase:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xlocale:11:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\stdexcept:10:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xstring:9:  
In file included from C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\xmemory:15:  

C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:81:10:   
error: missing 'typename' prior to dependent type name '_It::iterator_category' typedef _It::iterator_category iterator_category;

C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:82:10:  
error: missing 'typename' prior to dependent type name '_It::value_type' typedef _It::value_type value_type;

C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:83:10:  
error: missing 'typename' prior to dependent type name '_It::distance_type' typedef _It::distance_type distance_type;

C:\Program Files (x86)\Microsoft Visual Studio\VC98\include\utility:224:32:  
error: template parameter redefines default argument  
 template < class _E, class _Tr = char_traits< _E > >  

...

我也试过:

$> clang++ file_cpp.cpp
$> clang -x c++ file_cpp.cpp

但我仍然得到同样的错误。

有人可以解释我怎么了?

4

1 回答 1

3

有某些标志(我认为是-fms-extensions,不太确定确切的选项)需要使 clang 解析 VC++ 标头。

您将遇到的下一个问题是生成的可执行文件无法链接。这是因为 clang 使用了与 MSVC 不同的名称修饰,并且会导致未定义的引用。

如果你想在 Windows 上使用 Clang(目前可以使用 MinGW-w64),你可以使用我的预构建包,你需要

  1. 铿锵声 3.2

  2. 海合会 4.6

解压到同一个目录。在这种情况下,GCC 仅用于调用链接器。Clang 可用于编译所有内容。

目前无法通过 Visual Studio 标头 + 库将 clang 用于 C++。C 应该可以工作,但我还没有测试过,可能还有其他 ABI 问题阻止它工作。

于 2013-05-23T07:53:08.730 回答