Skip to content
Latchkey

lld: Usage, Options & Common CI Errors

lld is LLVM’s drop-in linker, often several times faster than GNU ld.

lld is the go-to for cutting link time on large C++ projects in CI. You almost never invoke it directly - you select it with -fuse-ld=lld through the compiler driver.

What it does

lld is the LLVM project linker. It is a faster, largely ld-compatible replacement that links ELF, COFF, and Mach-O. In practice you enable it via the compiler driver so the correct startup files and search paths are still passed.

Common usage

Terminal
clang main.o util.o -o app -fuse-ld=lld
g++ main.o -o app -fuse-ld=lld
clang -o app *.o -fuse-ld=lld -Wl,--threads=8
ld.lld --version
clang main.o -o app -fuse-ld=lld -Wl,-rpath,/opt/lib

Options

FlagWhat it does
-fuse-ld=lldTell the compiler driver to use lld
-Wl,--threads=NParallelize the link
-Wl,-rpath,<dir>Pass an rpath through the driver
ld.lldThe bare linker binary
-Wl,--gc-sectionsDrop unused sections (smaller binary)

Common errors in CI

"collect2: fatal error: cannot find ‘ld.lld’" or "-fuse-ld=lld: invalid linker name" means lld is not installed - install the lld package (apt-get install lld). lld rejects a few obscure GNU ld linker-script directives; if a custom -Wl,-T script fails, either port it or fall back to -fuse-ld=bfd. Symbol/undefined-reference errors mean the same thing as with ld - a missing library or wrong link order, not a linker bug.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →