Skip to content

Build LLVM from source code on Windows 10

ApsarasX edited this page Mar 1, 2022 · 5 revisions

Background

You may have installed LLVM by installing the package LLVM-13.0.1-win64.exe or executing the command choco install llvm.

But LLVM installed in these ways is not a complete LLVM, missing many library files and cmake files.

It's recommended to install LLVM by building from source code.

Preparation

You need to install some tools before building LLVM source code.

1. Visual Studio

You can refer to https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2022 for more details.

Please be sure to choose the Desktop development with C++ workload, otherwise you will not be able to build LLVM.

2. CMake

You can download the package cmake-3.23.0-rc2-windows-x86_64.msi to install, or execute the command choco install cmake to install.

Build

First, you need to download llvm-13.0.1.src.tar.xz, and unzip it to a specific directory, assuming C:\Users\dev\llvm-13.0.1.src.

Then, execute the following command to build LLVM.

# enter the source directory
cd C:\Users\dev\llvm-13.0.1.src

# create build directory
mkdir build

# enter the build directory
cd build

# configure projects by cmake
cmake -Thost=x64 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_INCLUDE_TESTS=OFF ..

# start building
cmake --build .

Finally, after compilation, the built LLVM will be located on C:\Users\dev\llvm-13.0.1.src\build.

Clone this wiki locally