title: How to build clang with libc++ as default via LLVMs build_docker_image.sh?
body: <p>I want to build a docker container with clang 6 and libc++ as default C++ standard library. I want to include (and use) the LLVM project clang, libcxx, libcxxabi, lld and compiler-rt.</p>
  
  <p>To set libc++ as default I used the CMAKE option <code>CLANG_DEFAULT_CXX_STDLIB=libc++</code> (and additionally <code>DCLANG_DEFAULT_RTLIB=compiler-rt</code> to default to compiler-rt). The first stage build does work, but it seems that libc++ is not installed:</p>
  
  <pre><code>$ git clone https://github.com/llvm-mirror/llvm.git
  $ cd llvm
  $ git checkout release_60
  $ utils/docker/build_docker_image.sh -s debian8 \
      -d "clang" -t "6" --branch branches/release_60 \
      -p compiler-rt -p libcxxabi -p libcxx -p clang \
      -i stage2-install-compiler-rt \
      -i stage2-install-libcxxabi \
      -i stage2-install-libcxx \
      -i stage2-install-clang \
      -i stage2-install-clang-headers -- \
      -DCMAKE_BUILD_TYPE=Release \
      -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
      -DCLANG_DEFAULT_RTLIB=compiler-rt \
      -DLIBCXXABI_USE_LLVM_UNWINDER=YES \
      -DCLANG_ENABLE_BOOTSTRAP=ON \
      -DBOOTSTRAP_CMAKE_BUILD_TYPE=Release \
      -DBOOTSTRAP_CLANG_DEFAULT_CXX_STDLIB=libc++ \
      -DBOOTSTRAP_CLANG_DEFAULT_RTLIB=compiler-rt \
      -DBOOTSTRAP_LIBCXX_USE_COMPILER_RT=YES \
      -DBOOTSTRAP_LIBCXXABI_USE_COMPILER_RT=YES \
      -DCLANG_BOOTSTRAP_TARGETS="install-compiler-rt;install-libcxxabi;install-libcxx;install-clang;install-clang-headers"
  </code></pre>
  
  <p>On second stage build I get:</p>
  
  <pre><code>[...]
  -- The C compiler identification is Clang 6.0.1
  -- The CXX compiler identification is Clang 6.0.1
  -- The ASM compiler identification is unknown
  -- Found assembler: /tmp/clang-build/build/./bin/clang
  -- Check for working C compiler: /tmp/clang-build/build/./bin/clang
  -- Check for working C compiler: /tmp/clang-build/build/./bin/clang -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /tmp/clang-build/build/./bin/clang++
  -- Check for working CXX compiler: /tmp/clang-build/build/./bin/clang++ -- broken
  CMake Error at /usr/local/share/cmake-3.7/Modules/CMakeTestCXXCompiler.cmake:44 (message):
    The C++ compiler "/tmp/clang-build/build/./bin/clang++" is not able to
    compile a simple test program.
  
    It fails with the following output:
  
     Change Dir: /tmp/clang-build/build/tools/clang/stage2-bins/CMakeFiles/CMakeTmp
  
  
  
    Run Build Command:"/usr/bin/ninja" "cmTC_d8e88"
  
    [1/2] Building CXX object CMakeFiles/cmTC_d8e88.dir/testCXXCompiler.cxx.o
  
    [2/2] Linking CXX executable cmTC_d8e88
  
    FAILED: : &amp;&amp; /tmp/clang-build/build/./bin/clang++
    CMakeFiles/cmTC_d8e88.dir/testCXXCompiler.cxx.o -o cmTC_d8e88 &amp;&amp; :
  
    /usr/bin/ld: cannot find -lc++
  
    clang-6.0: error: linker command failed with exit code 1 (use -v to see
    invocation)
  
    ninja: build stopped: subcommand failed.
  
  
  
  
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:45 (project)
  [...]
  </code></pre>
  
  <p>A single stage build seems to be done successfully:</p>
  
  <pre><code>$ git clone https://github.com/llvm-mirror/llvm.git
  $ cd llvm
  $ git checkout release_60
  $ utils/docker/build_docker_image.sh -s debian8 \
      -d "clang-1stage" -t "6" --branch branches/release_60 \
      -p compiler-rt -p libcxxabi -p libcxx -p clang \
      -i install-compiler-rt \
      -i install-libcxxabi \
      -i install-libcxx \
      -i install-clang \
      -i install-clang-headers -- \
      -DCMAKE_BUILD_TYPE=Release \
      -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
      -DCLANG_DEFAULT_RTLIB=compiler-rt
  </code></pre>
  
  <p>But when I run the container there are also problems with linking:</p>
  
  <pre><code>$ docker run -it clang:6
  root@1e95a7ffe57a:/# echo "#include &lt;iostream&gt;" &gt; main.cpp
  root@1e95a7ffe57a:/# echo "int main(){ std::cout &lt;&lt; \"Hello World\\n\"; }" &gt;&gt; main.cpp
  root@1e95a7ffe57a:/# clang++ main.cpp 
  /usr/bin/ld: /tmp/main-7d03e7.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
  //lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
  clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>What am I doing wrong?</p>