Last Updated: February 25, 2016
·
5.137K
· killwing

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.git

get clang

cd $LLVMDIR/tools
git clone http://llvm.org/git/clang.git

get clang tools (optional)

cd $LLVMDIR/tools/clang/tools
git clone http://llvm.org/git/clang-tools-extra.git extra

get comipler-rt

cd $LLVMDIR/projects
git clone http://llvm.org/git/compiler-rt.git

get libcxx

cd $LLVMDIR/projects
git clone http://llvm.org/git/libcxx.git

get libcxxabi

cd $LLVMDIR/projects
git clone http://llvm.org/git/libcxxabi.git

Update: 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 default

build 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 tests

build 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 install

Usage

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

2 Responses
Add your response

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?

over 1 year ago ·

@Seok-Hong i'm not sure build with cmake v2.8 but you can try first.

over 1 year ago ·