Clang在Windows上 [英] Clang on Windows

查看:432
本文介绍了Clang在Windows上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我遵循入门:构建和运行ang。特别是,我已经根据使用Visual Studio部分构建它。换句话说,我使用Visual Studio 2010构建它。



其次,我手动设置include和library路径到MinGW分发:



>



我试图编译的简单程序:

  #include< iostream> 
using namespace std;

int main(){
cout<< 你好,世界! << endl;
return 0;
}



我从编译器获得以下反馈:

 在C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \iostream中包含的文件中: 39:
在从C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \ostream:39:
包含的文件中从C :\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \ios:38:
在从C:\MinGW\lib\gcc\\中包含的文件中\\mingw32\4.5.2\include\c ++ \iosfwd:41:
在包含在C:\MinGW\lib\gcc\mingw32\4.5.2\include\\中的文件中\\ c ++ \bits / postypes.h:41:
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \cwchar:144:11:错误:在全局命名空间中没有名为'fgetws'的成员
using :: fgetws;
~~ ^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \cwchar:146:11:错误:没有成员命名为 fputws'在全局命名空间
中使用:: fputws;
~~ ^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \cwchar:150:11:错误:没有成员名为 getwc'在全局命名空间
中使用:: getwc;
~~ ^
C:\MinGW\lib\gcc\mingw32\4.5.2\include\c ++ \cwchar:151:11:错误:没有成员名为 getwchar'在全局命名空间
中使用:: getwchar;
~~ ^
C:\MinGW\lib\gcc\mingw32\4.5.2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ cwchar: putwc'在全局命名空间
中使用:: putwc;
~~ ^
C:\MinGW\lib\gcc\mingw32\4.5.2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ putwchar'在全局命名空间
中使用:: putwchar;
~~ ^
产生6个错误。
生成错误,生成停止
耗时:646毫秒。

显然的问题是 - 为什么要这样?



此外,我想了解更多细节,自从Clang网站提供了非常简短的信息 - 我想有人可以澄清以下问题给我:


  1. 据我所知,Clang没有自己的标准库(stdc ++我猜,不是吗?)。

  2. 使用Visual Studio和MinGW构建Clang有什么区别?

  3. 这是为什么我必须使用MinGW的标题和库 - 我必须在 clang / lib / Frontend / InitHeaderSearch.cpp 中硬编码包含路径,或者我可以跳过它,而是稍后通过-I选项指定这些路径
  4. 如果您使用MSVS构建Clang,它将自动执行搜索默认的VS包含路径,并拉入那些头。这是libstdc ++头产生错误的原因:它们正在导入VS头中不存在的C函数。使用Clang for C ++与VS现在是一个no-go:你会得到链接失败,由于在Clang中缺少ABI(名称调整和其他)功能。如果您仍然要使用MSVS Clang,请不要将其指向MinGW标头。它将解析VS头文件(包括C ++),它只是无法链接。






    strong>:我已经构建了一个dw2版本的GCC(仅32位),伴随Clang。异常在此构建中工作,因此您可以在Windows上使用Clang构建真正的C ++内容。 在此处获取版本3.2。


    First of all, I've followed "Getting Started: Building and Running Clang". In particular, I've built it according to "Using Visual Studio" section. In other words, I've built it using Visual Studio 2010.

    Secondly, I've manually set include and library paths to MinGW distribution:

    The simple program I'm trying to compile:

    #include <iostream>
    using namespace std;
    
    int main() {
        cout << "Hello, World!" << endl;
        return 0;
    }
    

    I get the following feedback from the compiler:

    In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iostream:39:
    In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ostream:39:
    In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\ios:38:
    In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\iosfwd:41:
    In file included from C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\bits/postypes.h:41:
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:144:11: error: no member named 'fgetws' in the global namespace
      using ::fgetws;
            ~~^
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:146:11: error: no member named 'fputws' in the global namespace
      using ::fputws;
            ~~^
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:150:11: error: no member named 'getwc' in the global namespace
      using ::getwc;
            ~~^
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:151:11: error: no member named 'getwchar' in the global namespace
      using ::getwchar;
            ~~^
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:156:11: error: no member named 'putwc' in the global namespace
      using ::putwc;
            ~~^
    C:\MinGW\lib\gcc\mingw32\4.5.2\include\c++\cwchar:157:11: error: no member named 'putwchar' in the global namespace
      using ::putwchar;
            ~~^
    6 errors generated.
    Build error occurred, build is stopped
    Time consumed: 646  ms.  
    

    The obvious question is - why do I get this?

    Additionally, I would like to know more details, and since, Clang website provides extremely brief information - I thought that somebody could clarify the following questions to me:

    1. As far as I understand Clang does not have its own standard library (stdc++ I guess, isn't it?). That's why I have to use MinGW's headers and libraries - am I right?
    2. What is the difference between building Clang with Visual Studio and MinGW?
    3. Do I have to hard-code include paths in clang/lib/Frontend/InitHeaderSearch.cpp or I can skip it and rather specify those paths later through "-I" option as I do in the screenshot above?

    解决方案

    If you build Clang with MSVS, it will automatically search the default VS include paths, and pull in those headers. This is the reason the libstdc++ headers are producing errors: they are importing C functions not present in the VS headers. Using Clang for C++ with VS is for now a no-go: you will get link failures due to missing ABI (name mangling and others) functionality in Clang. If you still want to use the MSVS Clang, don't point it to MinGW headers. It will parse the VS headers (including C++), it just will fail to link.


    EDIT: I have built a dw2 version of GCC (32-bit only) accompanied by Clang. Exceptions work in this build, and so you can build real C++ stuff with Clang now on Windows. Get version 3.2 here.

    这篇关于Clang在Windows上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆