让 Clang 在 Windows 上工作

发布于 2024-11-17 13:07:37 字数 1384 浏览 3 评论 0原文

我遵循了以下分步指南,经过一番摆弄后,我成功地编译了 clang使用代码:blocks 和 MinGW。太棒了,现在我可以将 Clang 模块添加到 eclipse 中(既然可以有四个 IDE,为什么还要一个)并开始编译。

我可以编译一个不使用标准库的简单程序,但不幸的是,当我尝试编译它时:

#include <iostream>
using namespace std;

int main()
{
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

首先我得到这个:

<块引用>

..\src\test.cpp:9:10:致命错误:找不到“iostream”文件

,因此我将 Mingw 标头添加到包含路径中;然后我得到这个:

'致命错误:'bits/c++config.h'文件 未找到'

这很奇怪。如果该文件不在“bits/”中,为什么 MingW 可以工作?它是内置于编译器中的吗?没关系,我找到它的实现并在“bits/”中创建文件。

然后我得到了一大堆错误,包括奇怪的错误,这些错误似乎表明 clang 没有正确实现预处理器,或者我对预处理器的理解不正确。

C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++/cwchar:45:26: error: expected value in expression
#if _GLIBCXX_HAVE_WCHAR_H

还有很多类似的事情。如果是的话

#if defined(_GLIBCXX_HAVE_WCHAR_H) 

#ifdef _GLIBCXX_HAVE_WCHAR_H?

那么 MinGW 标准库是错误的。

我认为我错误地认为可以使用 clang 来替代 gcc,并且它并非设计用于与 gnu 标准库一起使用。任何对此的确认或否认,并有证据支持,都将受到欢迎!

那么,有人有一种万无一失的方法可以在 Windows PC 上进行 clang 编译吗?网上缺乏有关 clang 的信息,尤其是有关 windows 的信息。

我真的很想让 clang 和 LLVM 工作起来,因为从我读到的内容来看,它们听起来很棒。任何帮助将不胜感激。

谢谢。

I have followed the following step by step guide and I've managed, after a bit of fiddling, to get clang to compile using code:blocks and MinGW. Great, so now I could add the Clang module to eclipse (why have one IDE when you can have four) and start compiling.

I can compile a simple program that doesn't use the standard library but unfortunately when I try to compile this:

#include <iostream>
using namespace std;

int main()
{
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

first of all I get this:

..\src\test.cpp:9:10: fatal error: 'iostream' file not found

so I add the Mingw headers to the include path; then I get this:

'fatal error: 'bits/c++config.h' file
not found'

which is weird. Why does MingW work if that file isn't in 'bits/'? Is it built in to the compiler?. Never mind, I find an implementation of it and create the file in 'bits/'.

Then I get a whole storm of errors including strange ones that seem to suggest either clang doesn't implement the preprocessor correctly or else my understanding of the preprocessor is incorrect.

C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++/cwchar:45:26: error: expected value in expression
#if _GLIBCXX_HAVE_WCHAR_H

and many more like that. Should that be

#if defined(_GLIBCXX_HAVE_WCHAR_H) 

or

#ifdef _GLIBCXX_HAVE_WCHAR_H?

If they are then the MinGW standard libraries are wrong.

I assume I'm incorrect in assuming that clang can be dropped in to replace gcc and that it is not designed to work with the gnu standard libraries. Any confirmation or denial of this, backed up with evidence would be most welcome!

So, does anybody have a foolproof way to get clang compiling on a Windows PC? There's a dearth of information online regarding clang and especially regarding windows.

I'm really keen to get clang and LLVM working as they sound great from what I've read. Any help would be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

时光瘦了 2024-11-24 13:07:37

此页面上有一些构建 clang 的说明(隐藏在“ Clang 开发”侧边栏的一部分...)。对于 MinGW,您需要名为“On Unix-like Systems”的部分。唯一棘手的部分是第 5 步,它告诉您如何设置 C++ 标准库的路径。这些需要添加到clang/lib/Frontend/InitHeaderSearch.cpp中的代码中。在我的机器上,它看起来像这样,

// FIXME: temporary hack: hard-coded paths.
AddPath("/usr/local/include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/mingw32", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/backward", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include-fixed", System, true, false, false);

尽管我不确定是否需要所有这些!

There's some instructions for building clang on this page (hidden in the "Clang Development" part of the sidebar...). For MinGW you want the section called "On Unix-like Systems". The only tricky part is step 5 which tells you how to set up the paths for the C++ standard library. These need to be added into the code in clang/lib/Frontend/InitHeaderSearch.cpp. On my machine it wound up looking like this

// FIXME: temporary hack: hard-coded paths.
AddPath("/usr/local/include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/mingw32", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/backward", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include", System, true, false, false);
AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include-fixed", System, true, false, false);

though I'm not sure all these are needed!

嘿看小鸭子会跑 2024-11-24 13:07:37

根据您的 MinGW 版本(以及移植的 gcc 版本),标头可能会有点分散......

在文件 clang/lib/Frontend/InitHeaderSearch.cpp 你会发现一些硬编码的路径。问题是每个版本都是特定的,因此如果您的 MinGW 版本不在其中,请随意添加它(并要求通过将补丁发布到 cfe-commit 将其集成到 Clang 的主线中)。

就我个人而言,我在 MinGW/msys 上运行它,只有一些小问题(许多测试用例失败,因为当...中存在 : 时,我的 msys shell 会破坏输入),我还没有尝试使用它不过,CodeBlocks(我习惯了命令行)。

如果您想提供帮助,Takumi 正在关注 MinGW 集成,Francois Pichet 正在领导与 VC++/MFC 标头的兼容性工作(即是主要贡献者)和 @rubenvb 目前正在尝试在 libc++ 上推送补丁,使其在 Windows 上运行(libc++ 尚未在 Windows 上编译)。这三个领域几乎是独立的,需要不同的技能和知识。

Depending on your version of MinGW (and thus the version of gcc ported), the headers might be scattered a bit...

In the file clang/lib/Frontend/InitHeaderSearch.cpp you will find a number of hard-coded paths. The trouble is that each is version specific, so if your version of MinGW is not in there, then feel free to add it (and ask for it to be integrated in Clang's mainline by posting the patch to cfe-commit).

Personally I run it on MinGW/msys with only minor issues (a number of test cases fail because my msys shell mangles the input when there are : in...), I have not tried using it from CodeBlocks though (I'm used to the command line).

If you wish to help, Takumi is watching over MinGW integration, Francois Pichet is leading the work on compatibility with VC++/MFC headers (ie is the main contributor) and @rubenvb is currently trying to push patches on libc++ to have it working on Windows (libc++ does not compile on Windows yet). The 3 areas are pretty much independent and require different skills and knowledge.

寂寞清仓 2024-11-24 13:07:37

我有类似的问题。我使用了由 Mike Dinsdale 的答案指定的 GCC 4.7 的类似路径,并使用“-isystem”标志(由 rubenvb 构建的 mingw64 发行版中的 Clang 3.2)将它们指定给我以后对 clang 可执行文件的所有调用(通过脚本)。由于这些目录被明确指定为系统包含目录,因此它们生成的所有可能令人厌烦的警告都会被自动抑制。

tl;dr:-isystem 标志指定 Clang 中的系统包含目录无需重新编译

I had a similar problem. I used the GCC 4.7's analogs of the paths specified by Mike Dinsdale's answer and specified them with the '-isystem' flag (Clang 3.2 in the mingw64 distribution as built by rubenvb) to all of my future calls to the clang executable (via scripts). As these directories are being specified explicitly as system inclusion directories, all potentially wearisome warnings generated by them are automatically suppressed.

tl;dr: the -isystem flag specifies system inclusion directories without recompilation in Clang

榆西 2024-11-24 13:07:37

Clang 确实有硬编码的搜索位置,如文件 clang/lib/Frontend/InitHeaderSearch.cpp 中定义,靠近注释 FIXME:临时 hack:硬编码路径

此页面上有一个关于它的注释:http://clang.llvm.org/get_started.html

因此,从其他编译器 (MingW) 获取包含路径,并将它们硬编码到 Clang 中,它可能可以工作。 (我不确定 Clang 的 Windows 支持是否达到 100%)

Clang does have hardcoded search locations, as defined in the file clang/lib/Frontend/InitHeaderSearch.cpp, near the comment FIXME: temporary hack: hard-coded paths.

There's a note about it on this page: http://clang.llvm.org/get_started.html

So get the include paths from your other compiler (MingW), and hardcode them into Clang, and it might work. (I'm not sure if Clang's Windows support is 100% there yet)

攒一口袋星星 2024-11-24 13:07:37

Windows 10 / VS 2017 / Clang 4.0.0 C 代码中缺少 stdlib.h。我是这样解决的:

  • 打开 x86_x64 Cross Tools Command Prompt for VS 2015/2016/2017。在这里运行 clang 应该可以消除“缺少标头”错误。
  • 如果仍然不起作用,则说明您缺少实际的标头和/或库,因为 Clang 将这些特定于平台的信息留给了 VS 或 MinGW。转到 \Program Files (x86)\Windows Kits\10\Include\ 并在其子目录(如果有)中搜索 stdlib.h 和 co。如果未找到,您需要安装最新的 Windows 10 SDK,方法是转到 Visual Studio(安装程序)并单击修改以添加包。

Windows 10 / VS 2017 / Clang 4.0.0 missing stdlib.h in C code. This is how I solved it:

  • Open x86_x64 Cross Tools Command Prompt for VS 2015/2016/2017. Running clang in here should eliminate the "missing headers" error.
  • If still not working, you are missing the actual headers and/or libs, since Clang leaves these platform-specifics to VS or MinGW. Go to \Program Files (x86)\Windows Kits\10\Include\ and search its subdirectories (if any) for stdlib.h and co. If not found, you will need to install the latest Windows 10 SDK by going to Visual Studio (installer) and clicking Modify to add packages.
愁杀 2024-11-24 13:07:37

当我遇到同样的问题时,我只需将代码块设置为我的设置的正确包含目录。它使用 -I 和 clang++ ,到目前为止一切都运行良好。

When I had the same issue, I just set-up Code Blocks to the correct include directories for my setup. And it uses -I with clang++ and everything's been working great so far.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文