Build llvm/clang on Linux
Requirements
GCC >= 4.7 (upgrade on ubuntu)
CMake >= 3.0
Get Source
Assume we get and build llvm in directory /local/llvm/,  set environment variable:
export LLVMDIR=/local/llvm/.
get llvm
cd /local
git clone http://llvm.org/git/llvm.gitget clang
cd $LLVMDIR/tools
git clone http://llvm.org/git/clang.gitget clang tools (optional)
cd $LLVMDIR/tools/clang/tools
git clone http://llvm.org/git/clang-tools-extra.git extraget comipler-rt
cd $LLVMDIR/projects
git clone http://llvm.org/git/compiler-rt.gitget libcxx
cd $LLVMDIR/projects
git clone http://llvm.org/git/libcxx.gitget libcxxabi
cd $LLVMDIR/projects
git clone http://llvm.org/git/libcxxabi.gitUpdate: use git pull --rebase instead of git pull to avoid non-linear history.
Building
build llvm/clang (gcc + automake)
cd $LLVMDIR
mkdir build
cd build
../configure --enable-optimized --disable-assertions    # release build
make -j8                                                # make use of 8 cores
make install                                            # /usr/local by defaultbuild libcxxabi (clang + cmake)
cd $LLVMDIR/projects/libcxxabi
mkdir build
cd build
CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release ..
make -j8
make install
make check-libcxxabi    # run testsbuild libcxx (clang + cmake)
cd $LLVMDIR/projects/libcxx
mkdir build
cd build
CC=clang CXX=clang++ cmake -DLIBCXX_CXX_ABI=libcxxabi -DLIBCXX_LIBCXXABI_INCLUDE_PATHS=$LLVMDIR/projects/libcxxabi/include -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_DIR=/usr ..    # install libc++ and headers (c++/v1) to /usr
make -j8
make installUsage
clang++ -std=c++11 -stdlib=libc++ helloworld.cpp -lc++abi
Reference
http://clang.llvm.org/get_started.html
http://compiler-rt.llvm.org/
http://libcxx.llvm.org/
http://libcxxabi.llvm.org/
http://llvm.org/docs/CMake.html
Written by kelviN
Related protips
2 Responses
 
thanks for your post.
i have a question to you.
"why we should use the cmake 3.0?"
i'm using linux mint, and the 2.8.12.2 still latest version in default.
should i build and install the cmake directly?
 
@Seok-Hong i'm not sure build with cmake v2.8 but you can try first.
 
 
 
 
