Clang通过命令行工作,但不通过SublimeClang(Win8x64)在Sublime Text中工作

时间:2012-11-03 14:04:40

标签: mingw clang sublimetext2

使用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”没有错误。


然后我使用Package Control为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默认为默认值?

2 个答案:

答案 0 :(得分:4)

我从#include <iostream>收到同样的错误,我可以通过定义__GNUC__=4__GNUC_MINOR__=7(显然,这是针对GCC 4.7)和{{1}来阻止它们}。

不幸的是,__MSVCRT__=1给我带来了一大堆其他错误:

#include <vector>

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

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

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> >'

答案 1 :(得分: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",
        "-"
    ]
}

由于-Idont_prepend_clang_includes部分是必需的。