如何编译锵在Windows [英] How to compile Clang on Windows

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

问题描述

我一直试图找到一种方式来获得锵在Windows上工作,但我有麻烦。我得到锵编译成功,但是当我尝试编译一个程序我都在标准头一堆错误的。

I have been trying to find a way to get Clang working on Windows but am having trouble. I get Clang to compile successfully, but when I try to compile a program I have a bunch of errors in the standard headers.

我知道<一个href=\"http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/\">rubenvb's铿锵优秀prebuilt版本,但我想编译它自己。我还听有关铛的GoingNative会谈里面说,它没有很好的Windows的支持呢。我怎样才能获得铛在Windows上工作?

I am aware of rubenvb's excellent prebuilt versions of clang, but I want to compile it for myself. I also was listening to the GoingNative talks about clang which said that it didn't have very good Windows support yet. How can I get clang working on Windows?

推荐答案

我用下面的方法来编译C ++铛在Windows 7和它已被Mysticial和其他有效的:

I used the following method to compile clang for C++ on Windows 7 and it has been validated by Mysticial and others:


  1. 下载并安装 MinGW的(使确保安装了C ++编译器),并把bin文件夹在你的PATH(我有MinGW的4.6.1和另一台计算机上的4.6.2测试成功)

  2. 确保您有的Python 在PATH(不3 ,我有2.7)

  3. (可选:请确保您有Perl在PATH(我用的ActivePerl 5.14.2 64位))

  4. CMake的,并把它放在你的PATH

  5. 转至 LLVM下载页面并下载LLVM 3.0源$ C ​​$ C沿铛源$ C ​​$ C。不要从SVN的code,它不与MinGW的头工作。

  6. 提取源$ C ​​$ CS;我曾在一个文件夹中名为LLVM-3.0.src LLVM的源代码在我的桌面

  7. 直接把铛源一个名为铛的文件夹在LLVM源文件夹中的工具文件夹(必须准确地叫,或者你将建立LLVM,但铿锵不会得到建),这应该使您的目录,如下所示:

    • LLVM源

      • autoconf的文件夹

      • ...

      • Tools文件夹

        • ...

        • 铛文件夹

          • 绑定文件夹

          • ...

          • 的Makefile文件

          • ...

  1. Download and install MinGW (make sure you install the C++ compiler) and put the bin folder in your PATH (I have MinGW 4.6.1 and tested successfully on another computer with 4.6.2)
  2. Make sure you have Python in your PATH (not 3, I have 2.7)
  3. (Optional: Make sure you have Perl in your PATH (I used ActivePerl 5.14.2 64-bit))
  4. Get CMake and put it in your PATH
  5. Go to the LLVM downloads page and download the LLVM 3.0 source code along with the Clang source code. Don't get the code from the SVN, it doesn't work with the MinGW headers.
  6. Extract the source codes; I had the llvm source in a folder named llvm-3.0.src on my desktop
  7. Put the clang source directly in a folder called "clang" (it must be called this exactly or you will build llvm but clang won't get built) in the "tools" folder inside the llvm source folder, this should make your directories look like:
    • llvm source
      • autoconf folder
      • ...
      • tools folder
        • ...
        • clang folder
          • bindings folder
          • ...
          • Makefile file
          • ...

运行命令的CMake -GMinGW的Makefile文件-DCMAKE_BUILD_TYPE =释放.. \\ LLVM-3.0.src


  • (最后一个参数是有它的LLVM源(和工具铛源/铛子目录)的文件夹的相对路径)

  • (the last argument is the relative path to the folder that has the llvm source in it (and the clang source in the tools/clang subdirectory))

这会做一个配置命令相同,并且Makefile,一切都将在build文件夹中生成

This will do the equivalent of a "configure" command, and the makefiles and everything will be generated in the build folder

运行命令的mingw32-化妆


  • 这将LLVM编译和铛,以及铛可执行文件将在build / bin文件夹中生成

  • 这可能会需要很长的时间。 (您可以尝试通过增加平行加快步伐建立, -j&LT;数&GT; 选项),这可能是件好事关闭所有其他程序,使您的电脑可以集中精力,并所以他们不与冗长的编译过程产生干扰,如把一个锁编译器写入(它发生在我身上)的文件夹上。我甚至关掉我的防病毒软件和防火墙软件,使他们不会试图扫描生成的文件和的方式获得。

  • This will compile llvm and clang, and the clang executables will be generated in the build/bin folder
  • This will probably take a long time. (You can try to speed it up by adding parallel builds, -j<number> option) It might be good to close all other programs so that your computer can concentrate, and so they don't interfere with the lengthy compilation process, such as putting a lock on a folder that the compiler is writing to (it happened to me). I even turned off my antivirus and firewall software so that they wouldn't try to scan the generated files and get in the way.

时间测试它


  1. 创建构建/ bin文件夹.cpp文件(我会用HELLO.CPP)。使用标准库的头,以确保包括路径和库工作。先从一个非常简单的程序。

  1. Create a .cpp file in the build/bin folder (I will use hello.cpp). Use a standard library header to make sure the include paths and libraries are working. Start with a very simple program.

(我开始用什么:

#include <iostream>

int main() {
    std::cout << "hi";
}

运行命令铛HELLO.CPP -std =的C ++ 0x -IC:\\ MinGW的\\ lib目录\\ GCC \\的mingw32 \\ 4.6.1 \\包括\\ C ++-I C:\\ MinGW的\\ lib目录\\ GCC \\的mingw32 \\ 4.6.1 \\包含\\ C ++ \\ mingw32的-Lc:/ MinGW的/ bin中/../ lib中/ GCC / mingw32的/ 4.6.1 -Lc:/ MinGW的/ bin中/ ../lib/gcc -Lc:/ MinGW的/ bin中/../ lib中/ GCC / mingw32的/ 4.6.1 /../../../../ mingw32的/ lib目录-Lc:/ MinGW的/ bin中/ ../lib/gcc/mingw32/4.6.1/../../ .. -L / MinGW的/ lib目录-lstdc ++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 - lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt

( - L指定要在其中搜索库的目录和-l指定库链接)
(如果您没有安装为我做了相同的路径MinGW的,你可以找到与该命令的路径G ++ somefile.cpp -v来获得G ++洒什么选项是使用该库路径的胆量和库文件和其他一切
搜索附近的输出为-L和-l选项的结束。要知道,穿插与-L年代的.o文件名。锵使用了许多的)相同的选项,G ++,所以我从字面上复制并粘贴从G ++的输出线

(-L specifies a directory in which to search for libraries and -l specifies a library to link) (If you do not have MinGW installed to the same path as I did, you can find out the paths with the command "g++ somefile.cpp -v" to get g++ to spill its guts about what options it is using for the library paths and library files and everything else Search near the end of the output for the -L and -l options. Be aware of the .o file names that are interspersed with the -L's. Clang uses many of the same options as g++ so I literally copied and pasted that line from the output of g++)

这应该编译你的程序,并产生一个名为a.out的

This should compile your program and produce a file named a.out

重命名的a.out到A.EXE或任何

rename a.out to a.exe or whatever

锵(3.0)仍然对Windows中的一些问题(我不知道,如果这些问题也是在Linux上)。例如,编译一个lambda(其中铛不支持)与-std =的C ++ 0x将导致铛崩溃,并发出诊断错误。
(我是在LLVM IRC获悉,这是因为铛工具解析为lambda表达式而不是语义分析,这是它崩溃的阶段(因为他们忘了禁用解析为3.0版本lambda表达式),他们已经知道这个BUG)

Clang (3.0) still has some problems on Windows (I don't know if these problems are also on linux). For example, compiling a lambda (which clang doesn't support) with -std=c++0x will cause clang to crash and emit a diagnostic error. (I was informed on the LLVM IRC that this is because clang implements parsing for lambdas but not semantic analysis, which is the phase in which it crashes (because they forgot to disable parsing lambdas for the 3.0 release), and they already know about this bug)

此外,杰出的Mysticial欣然同意来测试本指南和他的测试期间取得了一些意见:

Also, the illustrious Mysticial kindly agreed to test this guide and made some observations during his testing:


  1. Windows头似乎工作。

  2. 目前仅适用于32位。

  3. 64位编译罚款,但不会安装。

  4. SSE可能是罚款。 ([Mysticial尚未]在32位,虽然测试工作SSE)。

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

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