LLVM2.7已经发布好几天了。今天尝试一下:)
1,下载相关源码包:
wget -c http://llvm.org/releases/2.7/llvm-2.7.tgz
wget -c http://llvm.org/releases/2.7/clang-2.7.tgz
wget -c http://llvm.org/releases/2.7/llvm-gcc-4.2-2.7.source.tgz
wget -c http://llvm.org/releases/2.7/llvm-test-2.7.tgz
llvm-2.7.tgz是LLVM的主要源码包,clang-2.7.tgz:Clang前端,llvm-gcc-4.2-2.7.source.tgz:GCC4.2前端,llvm-test-2.7.tgz:LLVM 测试验证包。
2,接下来就是解压源码:
因为LLVM官方已经很自信clang的正确性了。本博打算只试试clang前端:)
注意,clang和llmv-test需要放在llvm源码中的指定位置。
解压缩LLVM-2.7源码
tar xzf llvm-2.7.tgz
解压缩Clang源码到llvm27/tools/clang/下
tar xzf llvm-tar/clang-2.7.tgz
cp -r clang-2.7 llvm-2.7/tools/clang
3,标准姿势,configure,make,make install
mkdir llvm-build
cd llvm-build
../llvm-2.7/configure --prefix=/home/lingcc --disable-optimize
make
make install
4.testsuite要特殊对待。
解压缩llvm-test-2.7.tgz到llvm-2.7/projects/test-suite/下
tar xzf llvm-tar/llvm-test-2.7.tgz
cp -r llvm-test-2.7 llvm-2.7/projects/test-suite
cd llvm-build
../llvm-2.7/configure --prefix=/home/lingcc --disable-optimize
cd llvm-build/projects/test-suite/
gmake
日后的改动,都可以在llvm-build/projects/test-suite/验证正确性。
5.快来!helloworld
#include
int main()
{
printf("hello,LLVM\n");
return 0;
}
直接生成可执行文件:
clang hello.c -o hello -v
使用-v选项能看到,clang负责生成了汇编文件.s,然后/usr/bin/gcc负责将汇编文件转为.o文件,进而生成hello可执行文件。
生成LLVM中间表示文件.bc:
clang hello.c -c -o hello.bc -emit-llvm -v
用LLVM虚拟机执行
lli hello.bc
看看输出结果是不是一致:)
转换为可读模式的LLVM中间表示:
llvm-dis < hello.bc
将LLVM中间表示转换为汇编语言文件:
llc hello.bc -o hello.s
汇编文件就可以直接使用GCC转换为可执行文件了
gcc hello.s -o hello.native
执行一下:
./hello.native
参考:
http://llvm.org/docs/TestingGuide.html#testsuiterun
http://llvm.org/docs/GettingStarted.html#installcf
http://llvm.org/docs/TestingGuide.html
http://llvm.org/releases/

请问我在安装test时遇到到这个问题是怎么回事啊?如何解决?
root@ubuntu:/home/changl/llvm-build-2.9/projects/test-suite# make
make[1]: Entering directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource’
make[2]: Entering directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests’
make[3]: Entering directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests/Vector’
make[4]: Entering directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests/Vector/SSE’
/usr/bin/llvm-gcc -I/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests/Vector/SSE -I/home/changl/llvm-2.9/projects/test-suite/SingleSource/UnitTests/Vector/SSE -I/home/changl/llvm-build-2.9/projects/test-suite/../../../llvm-2.9/projects/test-suite/include -I../../../../include -I/home/changl/llvm-build-2.9/include -I/home/changl/llvm-2.9/include -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -DNDEBUG -O3 -mllvm -disable-llvm-optzns -msse2 -m64 -fomit-frame-pointer -S /home/changl/llvm-2.9/projects/test-suite/SingleSource/UnitTests/Vector/SSE/sse.expandfft.c -o Output/sse.expandfft.ll -emit-llvm
cc1: warning: unrecognized gcc debugging option: i
cc1: warning: unrecognized gcc debugging option: s
cc1: warning: unrecognized gcc debugging option: b
cc1: warning: unrecognized gcc debugging option: l
cc1: warning: unrecognized gcc debugging option: e
cc1: warning: unrecognized gcc debugging option: -
cc1: warning: unrecognized gcc debugging option: l
cc1: warning: unrecognized gcc debugging option: l
cc1: warning: unrecognized gcc debugging option: m
cc1: warning: unrecognized gcc debugging option: -
cc1: warning: unrecognized gcc debugging option: o
cc1: warning: unrecognized gcc debugging option: t
cc1: warning: unrecognized gcc debugging option: z
cc1: warning: unrecognized gcc debugging option: n
cc1: warning: unrecognized gcc debugging option: s
cc1: error: unrecognized command line option “-mllvm”
Incompatible plugin version
cc1: error: Fail to initialize plugin /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/plugin/dragonegg.so
make[4]: [Output/sse.expandfft.ll] Error 1 (ignored)
/home/changl/llvm-build-2.9/Release/bin/llvm-as Output/sse.expandfft.ll -o Output/sse.expandfft.bc
/home/changl/llvm-build-2.9/Release/bin/llvm-as: Output/sse.expandfft.ll: Could not open input file: No such file or directory
make[4]: *** [Output/sse.expandfft.bc] Error 1
make[4]: Leaving directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests/Vector/SSE’
make[3]: *** [all] Error 1
make[3]: Leaving directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests/Vector’
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource/UnitTests’
make[1]: *** [UnitTests/.makeall] Error 2
make[1]: Leaving directory `/home/changl/llvm-build-2.9/projects/test-suite/SingleSource’
make: *** [SingleSource/.makeall] Error 2
为什么我按照你的编译,提示makefile:18: Makefile.programs: 没有那个文件或目录
你在哪一步遇到的这个问题。 我在源码目录下find Makefile.programs
find . -name Makefile.programs
./llvm-2.7/projects/test-suite/Makefile.programs
./llvm-build/projects/test-suite/Makefile.programs
你能在源码或者build目录下找到这个文件吗?下载testsuite了吗?
大牛,如何在windows上完成llvm编译及安装,help
你好,我对windows安装不熟悉,所以无法给出具体意见。不过我google了一下,这个可能对你有用 http://adrianboeing.blogspot.com/2009/05/llvm-for-beginners-windows.html
如果访问不了的话,试试这个代理,在框内输入上面的网址就行。
http://pysproxy.appspot.com/
[...] 03: 安装LLVM2.7 step by step (5) [...]
慢慢看,挺详细
@qq微博, 呵呵,遇到什么问题,欢迎来讨论:)
现在的LLVM支持使用CMake进行构建。
http://dreamhead.blogbus.com/logs/62862705.html
@dreamhead, 谢谢告知。刚刚试了一把,确实很好用:) 不过这个不是linux系统的标配,只能希望它日后能逐渐成为主流。
@erlv, Test 回复