3

使用 MinGW 4.7.0,MSYS 编译的 Clang 3.2。

我通过自动安装程序/下载器获得了 MinGW,并按照以下说明构建了 Clang:http: //bencode.net/clangonwindows


在 PowerShell 上调用“g++ --version”会返回:enter code here

在 PowerShell 上调用“clang -v”会返回:clang version 3.2 (trunk 167353) Target: i686-pc-mingw32 Thread model: posix


我创建了一个小测试文件来检查 clang 是否正常工作,“test.cpp”:

#include <iostream>

class clangIsCool
{
    public:
        int x;
        int y;
};

int main() 
{
    clangIsCool *c; 
    std::cout << c->x * 10;

    return 0;
}

调用“clang++ test.cpp”没有错误。


然后我使用包控制为 SublimeText2 获得了 SublimeClang。

SublimeClang 可以在这里找到:https ://github.com/quarnster/SublimeClang

在 SublimeText2 中加载“test.cpp”并尝试编译给了我这些错误:

C:/MinGW/include\wctype.h:99,33 - Error - definition of variable with array type needs an explicit size or an initializer
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:145,11 - Error - no member named 'fgetws' in the global namespace
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:147,11 - Error - no member named 'fputws' in the global namespace
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:151,11 - Error - no member named 'getwc' in the global namespace
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:152,11 - Error - no member named 'getwchar' in the global namespace
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:157,11 - Error - no member named 'putwc' in the global namespace
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\cwchar:158,11 - Error - no member named 'putwchar' in the global namespace
C:/MinGW/include\ctype.h:112,33 - Error - redefinition of '_ctype'
C:/MinGW/include\ctype.h:112,33 - Error - definition of variable with array type needs an explicit size or an initializer
C:/MinGW/include\ctype.h:117,34 - Error - redefinition of '_pctype_dll'

我检查了 SublimeClang 的设置,这是 clang 使用的选项:

"options":
[
    "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/",
    "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1",
    "-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/",
    "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include",
    "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include\\c++",
    "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include\\c++\\mingw32",
    "-isystem", "C:\\MinGW\\include",
    "-Wall"
],

我尝试弄乱包含路径(即使它们看起来对我来说是正确的),但错误仍然存​​在。

我应该在 SublimeClang 的选项中包含任何其他路径吗?

有没有办法查看默认情况下clang使用的路径(因为它可以从命令行工作),以便我可以将它们与默认的SublimeClang进行比较?

4

2 回答 2

4

我 从. #include <iostream>_ __GNUC__=4___GNUC_MINOR__=7__MSVCRT__=1

不幸的是, #include <vector>给我带来了一大堆其他错误:

C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/alloc_traits.h:56,35 - Error - in-class initializer for static data member is not a constant expression
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/alloc_traits.h:86,24 - Error - type 'int' cannot be used prior to '::' because it has no members
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\ext/alloc_traits.h:105,11 - Error - using declaration refers into '_Base_type::', which is not a base class of '__alloc_traits<int>'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\ext/alloc_traits.h:106,11 - Error - using declaration refers into '_Base_type::', which is not a base class of '__alloc_traits<int>'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\ext/alloc_traits.h:107,11 - Error - using declaration refers into '_Base_type::', which is not a base class of '__alloc_traits<int>'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\ext/alloc_traits.h:108,11 - Error - using declaration refers into '_Base_type::', which is not a base class of '__alloc_traits<int>'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\ext/alloc_traits.h:109,11 - Error - using declaration refers into '_Base_type::', which is not a base class of '__alloc_traits<int>'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:81,16 - Error - base specifier must name a class
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:235,13 - Error - using declaration refers into '_Base::', which is not a base class of 'vector<int, std::allocator<int> >'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:236,13 - Error - using declaration refers into '_Base::', which is not a base class of 'vector<int, std::allocator<int> >'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:237,13 - Error - using declaration refers into '_Base::', which is not a base class of 'vector<int, std::allocator<int> >'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:238,13 - Error - using declaration refers into '_Base::', which is not a base class of 'vector<int, std::allocator<int> >'
C:/MinGW/lib/gcc/mingw32/4.7.0/include/c++\bits/stl_vector.h:527,13 - Error - using declaration refers into '_Base::', which is not a base class of 'vector<int, std::allocator<int> >'

我只能假设这也是由于更多的缺失或错误定义。但是,我尝试添加 g++ 提供的每个定义(http://stackoverflow.org/wiki/What_are_the_default_defines_in_my_Gnu_compiler?)但它似乎没有任何效果(除了添加大量宏重新定义的警告之外)。

我的 SublimeClang 项目设置如下(默认设置不变):

"sublimeclang_additional_language_options":
{
  "c++" : ["-std=c++11"]
},

"sublimeclang_options":
[
  "-D__GNUC__=4",
  "-D__GNUC_MINOR__=7",
  "-D__MSVCRT__=1",
  "-IC:\\project-specific-source",
  "-IC:\\project-specific-library\\include",
  "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include",
  "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include\\c++",
  "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.7.0\\include\\c++\\mingw32",
  "-isystem", "C:\\MinGW\\include",
  "-Wall",
  "-ferror-limit=0"
]
于 2012-11-17T10:25:52.067 回答
2

我有同样的错误,这是因为 llvm 是用不同版本的 mingw+gcc 构建的。我尝试自己构建clang,但没有帮助。今天我通过从这里安装 mingw+gcc 解决了这个问题:

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-dw2-4.6-release/i686-w64-mingw32-gcc-dw2-4.6.3-2-release-win32_rubenvb.7z/download

从这里发出叮当声:

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/clang-3.2-release/i686-w64-mingw32-clang-3.2-release-win32_rubenvb.7z/download

将所有内容放在同一个文件夹中,以便 bot g++.exe 和 clang++.exe 位于同一个 bin 文件夹中,并将该 bin 文件夹放在您的 PATH 中。

这是我现在的 sublimeclang 配置:

{
    "additional_language_options":
    {
        "c++" : ["-std=c++11",
                 "-ID:\\Apps\\mingw32-gcc-dw2-4.6.3-2-clang-3.2-win32\\i686-w64-mingw32\\include"]
    },

    "options":
    [
        "-g",
        "-O2",
        "-Wall",
        "-Wextra"
    ],

    "debug_options": false,

    "dont_prepend_clang_includes": true,

    "analyzer_commandline":
    [
        "clang.exe",
        "--analyze",
        "-o",
        "-"
    ]
}

-I部分是必需的,因为dont_prepend_clang_includes.

于 2013-02-16T17:57:33.500 回答