Downloading the official prebuilt LLVM/Clang binaries for Linux often comes with a shock: after extraction, the directory can easily exceed 10 to 11 GB. If your goal is simply to compile C and C++ programs, you do not need the vast majority of this payload. Most of that space is occupied by static library archives (.a files), LLVM development headers, helper tools, and unstripped debug symbols.

Why is the LLVM Package So Massive?

The official LLVM release is built for developers who want to extend LLVM, write compiler plugins, or build their own tools on top of the LLVM framework. For standard C/C++ compilation, you only need the frontend compiler driver (clang), its dependent shared libraries, and its built-in resource headers.

The Absolute Minimal Directory Structure

To compile C and C++ successfully on Linux (such as Debian 13.5), you can strip LLVM down to under 150 MB. Here is the minimal directory structure you must preserve:

clang-minimal/
├── bin/
│   ├── clang (and/or clang-22)
│   └── clang++ -> clang
└── lib/
    ├── clang/
    │   └── 22.1.8/
    │       └── include/      <-- CRITICAL: Contains compiler-specific headers
    ├── libclang-cpp.so.22
    └── libLLVM-22.so

Step-by-Step Guide to Stripping LLVM/Clang

Follow these steps to safely delete the unnecessary files without breaking your C/C++ compiler toolchain.

Step 1: Identify and Keep Essential Binaries

Navigate to the bin/ directory. By default, it contains dozens of executables like llvm-as, bugpoint, and opt. You only need the compiler drivers:

  • clang: The C compiler.
  • clang++: Usually a symlink to clang, used for C++ compilation.

If you plan on using LLVM's linker or archiver, you may also want to keep ld.lld and llvm-ar. Otherwise, Clang will fall back to using the system's GNU linker (ld) and archiver (ar).

Step 2: Preserve the Clang Resource Directory (Crucial)

The most common mistake when shrinking LLVM is deleting the lib/clang/<version>/ directory.

While Clang relies on your system's C/C++ standard library (e.g., GNU libstdc++ and glibc on Debian), it requires its own internal headers for compiler intrinsics and standard definitions. These are located in lib/clang/22.1.8/include/ and include vital files like:

  • stdarg.h
  • stddef.h
  • limits.h
  • float.h

If you delete this directory, compilation will fail with errors stating that basic types or headers cannot be found.

Step 3: Keep Only Necessary Shared Libraries

You can delete all static libraries (.a files) inside the lib/ directory. They are only needed if you are linking against LLVM programmatically.

To find out exactly which shared libraries (.so files) the clang binary depends on, run the ldd command:

ldd bin/clang

Typically, Clang dynamically links to libLLVM-22.so and libclang-cpp.so.22. Keep these files and delete all other .so files inside lib/.

Step 4: Safely Delete Unused Directories

You can safely delete the following directories entirely:

  • include/: Contains C++ headers for LLVM development, not standard C/C++ library headers.
  • share/: Contains documentation, man pages, and CMake configuration files.
  • libexec/: Contains helper tools not required for basic compilation.

Step 5: Strip Debug Symbols

Prebuilt binaries often contain debug symbols that bloat their size. You can significantly reduce the size of the remaining binaries and shared libraries by running the strip command:

strip --strip-unneeded bin/clang
strip --strip-unneeded lib/libLLVM-22.so
strip --strip-unneeded lib/libclang-cpp.so.22

System Prerequisites on Debian

Remember that a minimal Clang installation on Linux does not ship with the C/C++ standard library headers or system libraries. Clang expects these to be provided by the host operating system. Ensure you have them installed via your package manager:

sudo apt update
sudo apt install build-essential

Verifying the Minimal Installation

Once you have cleaned up the directory, verify that your minimal Clang compiler works by compiling a simple "Hello World" program:

./bin/clang++ -O3 main.cpp -o main
./main

By following this optimization process, you can easily reduce your LLVM installation footprint from 11 GB down to roughly 120-150 MB while maintaining full C and C++ compilation capabilities.