使用 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-mingw32Thread 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 默认使用的路径进行比较?

最佳答案

我从 #include <iostream> 得到了同样的错误,我能够通过定义 __GNUC__=4__GNUC_MINOR__=7 (显然,这是针对 GCC 4.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"
]

关于mingw - Clang++ 通过命令行工作,但不能通过 Sublime Clang (Win8x64) 在 Sublime Text 上工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13209891/

10-12 16:48