Build LLVM From Source

Quickly had LLVM 17.0.3 built from source again. Just follow the official website:

1. Git clone

1
2
$ ➜ git clone https://github.com/llvm/llvm-project.git
$ ➜ cd llvm-project

2. CMake Configure

There is a very serious pitfall here, please refer to LLVM CMake documentation

For LLVM-related variable LLVM_ENABLE_PROJECTS, if you want to build ALL projects by specifying -DLLVM_ENABLE_PROJECTS=all, all the following projects clang;clang-tools-extra;cross-project-tests;libc;libclc;lld;lldb;openmp;polly;pstl are to be built. Particularly, libc is also to be built, which will bring me the following error:

1
2
....../llvm-project/libc/src/string/strcpy.cpp:17:28: error: ‘char*__llvm_libc_18_0_0_git::strcpy(char*, const char*)’ aliased to external symbol ‘strcpy’
17 | LLVM_LIBC_FUNCTION(char*, strcpy,

Therefore, it's better to avoid building libc.

1
2
3
4
5
6
$ ➜ llvm-project git:(main)  cmake -S llvm-project/llvm -B llvm-project/build \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb" \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DBUILD_SHARED_LIBS=Onhexo

3. Build

1
$ ➜ llvm-project git:(main) cmake --build llvm-project/build -j16

4. Installation

1
$ ➜ llvm-project git:(main) sudo cmake --install llvm-project/build --prefix /usr/local