installing a complete clang++ environment

I try to use clang 3.6 for c++ development. I found a "clang+llvm-3.5.0-x86_64-fedora20.tar.xz" binary. But compiling with it results in:

/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../include/c++/4.8.3/cstdio:120:11: error: no member named 'gets' in the global namespace

which shows that clang uses my system installed stdlibc++ which is not what I want.

After searching a lot I found that I should set:
CXXFLAGS=-stdlib=libc++ -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc

which simply results in:
/usr/bin/ld: cannot find -lc++
/usr/bin/ld: cannot find -lc++abi

OK, both libs are not part of the binary prebuild.

Where can I find the needed libraries? If not, how can I compile a complete clang++? And how to install them?

Is there any full documentation about clang installing and first steps for using tutorial?

My problem is that I could find a lot of information, but nothing is complete. Each page I found give only a piece of information and combining all the infos results in incompatible solutions.


I perform the next steps to get working Clang and libc++ on my Gentoo box:

1) Download packages llvm-3.5.0.src.tar.xz, lldb-3.5.0.src.tar.xz,
libcxx-3.5.0.src.tar.xz, libcxxabi-3.5.0.src.tar.xz,
compiler-rt-3.5.0.src.tar.xz, cfe-3.5.0.src.tar.xz,
clang-tools-extra-3.5.0.src.tar.xz from

2) Extract them:
$ mkdir -pv ~/src/llvm/release_35

$ tar xfv llvm-3.5.0.src.tar.xz --strip-components=1 -C

$ mkdir -pv ~/src/llvm/release_35/projects/{libcxx,libcxxabi,compiler-rt}
$ tar xfv libcxx-3.5.0.src.tar.xz --strip-components=1 -C
$ tar xfv libcxxabi-3.5.0.src.tar.xz --strip-components=1 -C
$ tar xfv compiler-rt-3.5.0.src.tar.xz --strip-components=1 -C

$ mkdir -pv ~/src/llvm/release_35/tools/{clang,lldb}
$ tar xfv cfe-3.5.0.src.tar.xz --strip-components=1 -C
$ tar xfv lldb-3.5.0.src.tar.xz --strip-components=1 -C

$ mkdir -pv ~/src/llvm/release_35/tools/clang/tools/extra
$ tar xfv clang-tools-extra-3.5.0.src.tar.xz --strip-components=1 -C

3) And compile using cmake and Clang 3.3 from Gentoo portages:
$ mkdir -pv ~/build
$ cd ~/build

$ CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake
-DCMAKE_BUILD_TYPE=Release ~/src/llvm/release_35/

$ make -j3
$ make install

4) As result I have working Clang with libc++ support. For linking with
libc++ it necessary to set LD_LIBRARY_PATH environment variable:
$ export LD_LIBRARY_PATH=~/opt/clang-3.5.0-release/lib/

And now I can use Clang with libc++:
$ ~/opt/clang-3.5.0-release/bin/clang++ -stdlib=libc++ -nodefaultlibs
-lc++ -lc++abi -lm -lc -lgcc_s -lgcc main.cpp
$ ./a.out
Hello off, world!

PS: sorry for my English :frowning:


What about (after keywording)

  # emerge libcxx clang

After that, a simple -stdlib=libc++ does the rest.


libcxx is masked in a stable branch of Gentoo. I don't want to mix branches.
And sometimes I compile libcxx from trunk.

Thanks for your reply!

After several hours of trying I can't get it to work! :frowning:

I run into trouble with:

[ 98%] Built target lldb-platform
[ 98%] Building CXX object tools/extra/clang-apply-replacements/CMakeFiles/clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o
In file included from /home/krud/work/clang_complett_aus_source/src/tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:17:
/home/krud/work/clang_complett_aus_source/src/tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h:19:10: fatal error:
      'clang/Tooling/Refactoring.h' file not found
#include "clang/Tooling/Refactoring.h"

Any hints?


Additional info:

After i patched tons of flags.make files to include the correct include path I can compile.
BUT a make install distroys my linux! The install goes to /usr/local/include/ instead of /opt...


OK, I will now install my system again! I'll be back in a few days...

Ups forgett to tell you that the install script also fails:

-- Installing: /usr/local/include/lldb/Symbol/TypeVendor.h
-- Installing: /usr/local/include/lldb/Symbol/ObjectContainer.h
-- Installing: /usr/local/include/lldb/Symbol/VerifyDecl.h
-- Installing: /usr/local/include/lldb/Symbol/TypeList.h
CMake Error at tools/lldb/scripts/cmake_install.cmake:36 (FILE):
  file INSTALL cannot find
Call Stack (most recent call first):
  tools/lldb/cmake_install.cmake:42 (INCLUDE)
  tools/cmake_install.cmake:70 (INCLUDE)
  cmake_install.cmake:61 (INCLUDE)

When I do this I install clang a directory whose name is in the path named by the envariable “CLANG_DIR”, and put the clang version in the envariable named “CLANG_VERSION”.

  1. Then I compile using the command
    “clang++ -nostdinc++ -std=c++11 -isystem ${CLANG_DIR}/lib/clang/${CLANG_VERSION}/include …”

  2. Then I link using the command

“clang++ -nostdinc++ -std=c++11 -L${CLANG_DIR}/lib -stdlib=libc++ -lc++”

I actually put all this in a CMakefile, and then generally forget what I have done.

Variants of this let me build boost, poco, log4cpp and some other standard libraries with clang and libc++.

For boost and poco you need to figure out how to use their build system, which is harrowing, but

possible. For autoconf style systems you need to train them to not use libstdc++, which they really,
really want to do. For me, this typically means editing the configure script after autoconf does its
generation magic, since I’m too impatient and bored to figure out what autoconf and automake really
are trying to do. (Log4cpp is an autoconf project.)

It's lldb fail. It puts its files to lib64/ directory, although the
installation script look them in lib/ directory. You can just copy all
files from ~/build/lib64/ to ~/build/lib/ before make install.
Try to compile clang without lldb and clang-extra-tools.

What distro do you use? It's a challenge to break Linux :slight_smile:

It kills my last clang compiler, because it was installed there :slight_smile: So I can't compile anymore with any sort of clang... The rest of the distro is partly affected because the used dynamic libs are also lost.

I am wondering why the install script ignores the target directory.

For the missing python??? things I simply removed the part of the install script. But I wonder if it did not work because python is installed on my system and it works.

And have you any idea why the build process must be handcrafted? I must fix so many files for additional include dirs. Could you compile and install without that? It feels quite hard to do a compile from sources and I am wondering that others can do it without such problems. And yes, why is there no actual documentation or maybe a simple bash script or Makefile for that?


I've written (and just updated) a script to bootstrap clang, including
the various support libraries, into an arbitrary prefix, see



I've written (and recently updated) a script to bootstrap clang,
including the various support libraries. It installs the whole tool
chain into an arbitrary prefix, see

There's now also Docker image that comes with the result of the script


Documentation is. But it's fragmented:
- How to build llvm and clang --
- How to build libc++ --
- How to build lldb --

I've built these tools on Ubuntu 14.04 recently. And I didn't fix or
edit anything. I just followed the steps I listed in my first message.
Anyway, try to compile it without lldb. Its build script seems buggy --

And what distro do you use?