# How to Set Up a Development Environment for LLVM: A Complete Guide

> Set up your LLVM development environment quickly. This guide details cloning llvm-project, configuring with CMake and Ninja, and enabling Clang and LLD projects for efficient LLVM development.

- Repository: [LLVM/llvm-project](https://github.com/llvm/llvm-project)
- Tags: getting-started
- Published: 2026-09-09

---

**Setting up an LLVM development environment requires cloning the llvm/llvm-project monorepo, configuring the build with CMake using Ninja as the generator, and selecting sub-projects like Clang and LLD via `-DLLVM_ENABLE_PROJECTS`.**

The LLVM project provides a robust compiler infrastructure used by languages like C++, Rust, and Swift. Whether you are contributing to the core libraries or building custom compiler front-ends, configuring a proper development environment is essential for productive work. This guide walks through the exact steps documented in the `llvm/llvm-project` repository to configure, build, and verify your LLVM installation.

## Prerequisites for Building LLVM

Before cloning the repository, ensure your system meets the minimum toolchain requirements documented in [`llvm/docs/GettingStarted.md`](https://github.com/llvm/llvm-project/blob/main/llvm/docs/GettingStarted.md).

### Host Compiler Requirements

LLVM requires a modern C++ compiler capable of building C++17 code. The minimum supported versions are:

- **Clang 5.0** or later
- **GCC 7.4** or later  
- **Visual Studio 2019 16.8** or later (on Windows)

You will also need **CMake ≥ 3.20**, **Python ≥ 3.8**, and standard Unix utilities including `git`, `make`, and `ninja`. On Linux distributions, install these via your package manager; on macOS, use Homebrew.

## Obtaining the LLVM Source Code

The llvm/llvm-project repository uses a monorepo structure containing the core LLVM libraries, Clang, LLD, and other sub-projects. Clone the repository using Git:

```bash
git clone https://github.com/llvm/llvm-project.git

```

For faster cloning with limited bandwidth or disk space, use a shallow clone:

```bash
git clone --depth 1 https://github.com/llvm/llvm-project.git

```

LLVM strictly separates source and build trees. Never build directly in the source directory. Instead, create a dedicated build folder:

```bash
cd llvm-project
mkdir build && cd build

```

## Configuring the Build with CMake

The build configuration logic resides in [`llvm/CMakeLists.txt`](https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt), which defines all available options and defaults. Run CMake from your build directory, specifying the path to the `llvm` subdirectory inside the source tree.

### Selecting Projects and Runtimes

Use `-DLLVM_ENABLE_PROJECTS` to specify which components to build beyond the core libraries. Common choices include `clang` (the C/C++ front-end), `lld` (the LLVM linker), and `polly` (the polyhedral optimizer). Use `-DLLVM_ENABLE_RUNTIMES` to include standard library implementations like `libcxx` and `libcxxabi`.

```bash
cmake -G Ninja \
      -DCMAKE_BUILD_TYPE=Debug \
      -DLLVM_ENABLE_PROJECTS="clang;lld" \
      -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
      -DLLVM_USE_LINKER=lld \
      -DCMAKE_INSTALL_PREFIX=$HOME/llvm-install \
      ../llvm

```

Key parameters explained:

- **`-G Ninja`**: Selects the Ninja build system for faster parallel builds compared to Make.
- **`-DLLVM_USE_LINKER=lld`**: Uses the LLVM linker instead of the system default, significantly reducing link times.
- **`-DCMAKE_BUILD_TYPE`**: Set to `Debug` for development (enables assertions), `Release` for optimized builds, or `RelWithDebInfo` for a balance.

### Optimizing Build Performance

For machines with limited RAM, limit parallel link jobs to prevent out-of-memory errors:

```bash
cmake -DLLVM_PARALLEL_LINK_JOBS=2 ../llvm

```

Enable assertions during development by ensuring `-DLLVM_ENABLE_ASSERTIONS=ON` is set (default in Debug builds), but disable this for production compiler builds.

## Building and Testing LLVM

Once configured, compile the entire suite using Ninja:

```bash
ninja

```

Run the regression test suite to verify correctness:

```bash
ninja check-llvm

```

Install the compiled artifacts, libraries, and headers to your specified prefix:

```bash
ninja install

```

## Verifying Your Installation

Confirm that the newly built tools function correctly by compiling a simple C program to LLVM bitcode and executing it with the LLVM interpreter (`lli`):

```bash

# Create a test file

echo 'int main() { return 0; }' > hello.c

# Compile to LLVM bitcode using your built clang

clang -O3 -emit-llvm hello.c -c -o hello.bc

# Execute with the LLVM interpreter

lli hello.bc

```

This workflow mirrors the simple example provided in the official [`GettingStarted.md`](https://github.com/llvm/llvm-project/blob/main/GettingStarted.md) documentation.

## Advanced Configuration Options

### Cross-Compiling LLVM

To build LLVM for a different target architecture (such as iOS or Windows from a Linux host), provide a CMake toolchain file. The repository includes platform-specific configurations in `llvm/cmake/platforms/`:

```bash
cmake -G Ninja \
      -DCMAKE_TOOLCHAIN_FILE=../llvm/cmake/platforms/iOS.cmake \
      -DLLVM_ENABLE_PROJECTS="clang;lld" \
      ../llvm

```

Review the files in `llvm/cmake/platforms/` to find or adapt a toolchain configuration for your target platform.

## Summary

- **Prerequisites**: Install Clang 5.0+/GCC 7.4+, CMake 3.20+, Python 3.8+, and Ninja before building.
- **Source Layout**: Clone the llvm/llvm-project monorepo and always build in a separate directory outside the source tree.
- **CMake Configuration**: Use `-DLLVM_ENABLE_PROJECTS` to select components and `-DLLVM_USE_LINKER=lld` to accelerate builds.
- **Build Commands**: Run `ninja` to compile, `ninja check-llvm` to test, and `ninja install` to deploy.
- **Verification**: Test your build by compiling C code to bitcode with `clang` and running it via `lli`.

## Frequently Asked Questions

### What is the minimum CMake version required for LLVM?

LLVM requires **CMake 3.20 or newer** as specified in [`llvm/docs/GettingStarted.md`](https://github.com/llvm/llvm-project/blob/main/llvm/docs/GettingStarted.md). Earlier versions will fail during configuration with errors regarding unknown CMake policies or generator expressions.

### How do I speed up LLVM linking on machines with limited RAM?

Add `-DLLVM_PARALLEL_LINK_JOBS=N` to your CMake configuration, where `N` is a number lower than your CPU core count. Additionally, ensure you set `-DLLVM_USE_LINKER=lld` to use the LLVM linker, which consumes less memory and links faster than GNU `ld` or `gold` on large binaries.

### Can I build only specific LLVM sub-projects?

Yes. Pass a semicolon-separated list to the `-DLLVM_ENABLE_PROJECTS` flag. For example, `-DLLVM_ENABLE_PROJECTS="clang;lld"` builds only Clang and the LLD linker alongside the core LLVM libraries. Omitting this flag builds only the core LLVM infrastructure without any front-ends or tools.

### Where are the LLVM header files located after installation?

Headers are installed to `$CMAKE_INSTALL_PREFIX/include/llvm/` (e.g., `~/llvm-install/include/llvm/`). The core API headers, including those for `Instruction` and `BasicBlock` classes, originate from `llvm/include/llvm/` in the source tree and are copied to the install prefix during `ninja install`.