Guide · Open source
How to use mold: install, build and link faster
Updated · written with AI from the project's own documentation and checked against our catalogue data
mold is an open-source linker, the final build step that combines compiled object files into one executable or shared library. It is a drop-in Unix linker replacement, so you can try it without changing your source code. This guide shows you how to build and install it, and how to tell your compiler to use it.
Quick start
- 1Clone the repository. Run git clone https://github.com/rui314/mold.git to download the source.
- 2Build the release binary. Enter the mold directory and run cargo build --release. The executable is written to target/release/mold.
- 3Install mold. Run sudo ./install-mold.sh to install mold under /usr/local, or set PREFIX to choose another location.
- 4Add the linker flag. Add -fuse-ld=mold to your compiler flags in your build system config. For GCC before 12.1.0, use the -B option instead.
- 5Rebuild and check the result. Run your normal build and compare the link time with your previous build.
What does a linker do and why does link time matter?
A build for a compiled language such as C, C++, or Rust has two phases. First, a compiler turns source files into object files (.o files). Then a linker takes all the object files and combines them into a single executable or shared library.
The linking phase can take a long time when the build output is large. mold aims to make this step faster, and the difference is most noticeable during rapid debug-edit-rebuild cycles.
Install mold: clone and build it
mold is written in Rust and built with Cargo. It requires Rust 1.95 or later; if your system's Rust is older, install the stable toolchain with rustup. You also need Git and a C compiler such as GCC or Clang, which you can install with your system's package manager.
- Rust 1.95 or later (or install via rustup)
- Git
- A C compiler such as GCC or Clang
git clone https://github.com/rui314/mold.git
cd mold
cargo build --releaseInstall mold under /usr/local
After building, the executable is target/release/mold. To install it under /usr/local, run the install script. To use a different prefix, set PREFIX. You can also run target/release/mold directly without installing it.
- Install under a different prefix by setting PREFIX, for example PREFIX=/usr.
sudo ./install-mold.shTell your compiler to use mold
On Unix, the compiler driver (such as cc, gcc, or clang) calls the linker, usually /usr/bin/ld, and your build system calls the driver. If your build system lets you add a compiler option, you can switch the linker to mold without changing your code.
For Clang and for GCC 12.1.0 or later, pass -fuse-ld=mold. Older GCC versions do not accept mold as a value for -fuse-ld, so you need the -B option instead. If you installed mold with the script, the directory /usr/local/libexec/mold is where GCC can find it.
- Clang: pass -fuse-ld=mold
- GCC 12.1.0 or later: pass -fuse-ld=mold
- GCC before 12.1.0: use the -B option pointing to /usr/local/libexec/mold
Check whether mold will help your build
mold's benefit is largest when linking is a real bottleneck. The README benchmarks compare lld, wild, and mold on nine large programs on an AMD Ryzen Threadripper 7980X and an Apple M1 Ultra, and they report wall-clock medians of three runs after a warm-up. For example, in the Threadripper debug-build results, mold linked TensorFlow 2.21 in 3.15s versus 50.73s for lld.
The benchmark numbers come from the author's own setup, so measure your own build before deciding. If linking already takes very little time, switching linkers will save you little.
- Look for slow link steps in your build output before switching.
- Compare a before and after build time on your own project.
What people use it for
- Speeding up debug-edit-rebuild cycles on large C or C++ programs
- Reducing link time in large Rust projects
- Trying a faster linker on a Linux machine with a supported architecture
- Using mold as the default linker for a project whose build system accepts compiler flags
Frequently asked questions
Is mold free to use?
Yes. mold is released under the MIT licence, and its source code is on GitHub at rui314/mold.
What do I need to install mold?
You need Rust 1.95 or later (or rustup to install it), Git, and a C compiler such as GCC or Clang. You clone the repository, build it with cargo build --release, and optionally install it with sudo ./install-mold.sh.
Does mold work on macOS or Windows?
The README describes mold as a Unix linker and gives Unix-style usage only. It lists a Windows release zip without detail, and it does not describe macOS support, so check the repository before relying on it there.
How do I make Clang or GCC use mold?
Pass -fuse-ld=mold to the compiler driver through your build system's config. For GCC before 12.1.0, the README says to use the -B option pointing to /usr/local/libexec/mold instead.
Is mold faster than lld?
The README reports that mold links faster than LLVM lld in its own benchmarks, with some programs several times faster. Results depend on the program and machine, so test with your own build.
What are the alternatives to mold?
Comparable linkers mentioned for this project are lld, wild, and gold. Compare them on your own build, since the README's benchmarks are the author's results.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
mold suits developers on Linux or other supported Unix systems who work on large C, C++, or Rust programs with slow link times, and who can pass a compiler flag through their build system. If you use macOS or Windows, if your builds link quickly already, or if you need full compatibility details the README does not document, pick a different linker such as lld, wild, or gold and test it first.
Install options & downloads