LLVM-3.0及以上

见上一篇:[LLVM、Clang安装及测试]

LLVM-2.9

1.选定一个目录,以下是我的配置

1
2
3
4
$ mkdir llvm-29
$ cd llvm-29
$ pwd
$ /home/katherine/LLVM/llvm-29

2.下载源码

1
$ svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_29/final llvm

此处目录为/home/katherine/LLVM/llvm-29/llvm,你可以把llvm改为你想要的目录名。

3.下载clang

1
2
$ cd llvm/tools
$ svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_29/final clang

4.此版本编译有bug,按patch修改:

1
2
3
4
5
6
7
8
9
10
11
diff -u -r llvm-2.9/lib/ExecutionEngine/JIT/Intercept.cpp src/lib/ExecutionEngine/JIT/Intercept.cpp
--- llvm-2.9/lib/ExecutionEngine/JIT/Intercept.cpp 2010-11-29 18:16:10.000000000 +0000
+++ src/lib/ExecutionEngine/JIT/Intercept.cpp 2013-09-27 12:11:02.464085889 +0100
@@ -50,6 +50,7 @@
#if defined(__linux__)
#if defined(HAVE_SYS_STAT_H)
#include <sys/stat.h>
+#include <unistd.h>
#endif
#include <fcntl.h>
/* stat functions are redirecting to __xstat with a version number. On x86-64

5.创建build目录,与src目录同级

1
2
3
4
$ pwd
$ /home/katherine/LLVM/llvm-29
$ mkdir build
$ cd build

6.编译

1
2
3
$ ../llvm/configure --enable-optimized --enable-assertions
$ make
$ make install