1.下载
git clone https://github.com/llvm/llvm-project.git
2. 编译
a. 创立build文件夹
cd llvm-project
mkdir build (in-tree build is not supported)
cd build
b.编译
cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm
make
sudo make install
3.测试
clang --help
clang file.c -fsyntax-only (check for correctness)
clang file.c -S -emit-llvm -o - (print out unoptimized llvm code)
clang file.c -S -emit-llvm -o - -O3
clang file.c -S -O3 -o - (output native machine code)
make check-clang
llvm从源码编译较简单,但是耗时比较长,建议编译同时做别的任务
参考: