Search code examples
c++linuxbuildllvm

How to use llvm toolchain on Linux always by default


I'm trying to build linux docker image, that will use clang and llvm libs (compiler-rt, libunwind, libc++, ...) for build always by default. I've seen this question, but it uses CMake variables. I want to not have to make any edits to the projects themselves, so that llvm is always used by default. How can I achieve this?


Solution

  • You have to build llvm with special flags (full info):

    -DLIBCXX_USE_COMPILER_RT=YES      # compiler-rt in libc++
    -DLIBCXXABI_USE_LLVM_UNWINDER=YES # libunwind in libc++
    -DCLANG_DEFAULT_CXX_STDLIB=libc++ # libc++ as std lib in clang by default
    -DCLANG_DEFAULT_RTLIB=compiler-rt # compiler-rt in clang by default
    

    And update cc/c++ links:

    update-alternatives --install /usr/bin/cc cc /usr/bin/clang 800 \ 
                        --slave /usr/bin/c++ c++ /usr/bin/clang++