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?
Asked
Active
Viewed 326 times
0
-
Like using g++ .... `CXX=g++ cmake ..` or `CXX=g++-9 cmake ..` is using llvm : `CXX=clang++ cmake ..` – Knud Larsen Dec 03 '21 at 08:56
-
@Knud Larsen It will use gcc stdlib anyway. – Igor Pugachev Dec 04 '21 at 00:09
1 Answers
2
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++

Igor Pugachev
- 604
- 1
- 5
- 14