Table of Contents
1 ビルドに必要なパッケージをインストール
LLVM/Clangのビルドに必要なパッケージをインストールします。
sudo yum-builddep -y llvm clang
2 cmakeをインストール
LLVM/Clangはcmake 2.8.12.2以上のバージョンを必要とします。CentOS 7のcmakeは2.8.11なのでFedora 22からcmake 3.2.2のsrc.rpmを持ってきてインストールします。
$ wget sudo yum-builddep -y cmake$ sudo yum install jsoncpp-devel python-sphinx$ rpmbuild –rebuild cmake-3.2.2-1.fc22.src.rpm$ sudo yum localinstall -y rpmbuild/RPMS/x86_64/*.rpm
cmake 3.2.2がインストールされました。
$ cmake –versioncmake version 3.2.2CMake suite maintained and supported by Kitware (kitware.com/cmake).
3 LLVM/Clangをダウンロードする
Clangのページに記載されている手順でソースコードを取得します。libcxxは必要ありません。
$ svn co llvm$ cd llvm/tools$ svn co clang$ cd clang/tools$ svn co extra$ cd ../../../projects$ svn co compiler-rt$ cd ../..
4 LLVM/Clangをビルドする
ビルド用のディレクトリをソースコードと分けることができるので、新たにディレクトリを作成して、そちらでビルドします。
$ mkdir llvm.build$ cd llvm.build$ cmake -G “Unix Makefiles” -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ../llvm$ make$ sudo make install
5 動作確認
コンパイルしてみます。
$ /usr/local/bin/clang –versionclang version 3.9.0 (trunk 271105)Target: x86_64-unknown-linux-gnuThread model: posixInstalledDir: /usr/local/bin$ echo ‘#include <stdio.h>int main(void) { printf(“hellon”); return 0; }’ > hello.c$ /usr/local/bin/clang -v hello.c -o helloclang version 3.9.0 (trunk 271105)Target: x86_64-unknown-linux-gnuThread model: posixInstalledDir: /usr/local/binFound candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5Candidate multilib: .;@m64Candidate multilib: 32;@m32Selected multilib: .;@m64 “/usr/local/bin/clang-3.9” -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/local/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.9.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/hiroom2 -ferror-limit 19 -fmessage-length 90 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-f190c1.o -x c hello.cclang -cc1 version 3.9.0 based upon LLVM 3.9.0svn default target x86_64-unknown-linux-gnuignoring nonexistent directory “/include”#include “…” search starts here:#include <…> search starts here: /usr/local/include /usr/local/bin/../lib/clang/3.9.0/include /usr/includeEnd of search list. “/usr/bin/ld” –hash-style=gnu –no-add-needed –build-id –eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/usr/local/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. -L/usr/local/bin/../lib -L/lib -L/usr/lib /tmp/hello-f190c1.o -lgcc –as-needed -lgcc_s –no-as-needed -lc -lgcc –as-needed -lgcc_s –no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o$ ./hellohello