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
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/libOptions
| Flag | What it does |
|---|---|
| -fuse-ld=lld | Tell the compiler driver to use lld |
| -Wl,--threads=N | Parallelize the link |
| -Wl,-rpath,<dir> | Pass an rpath through the driver |
| ld.lld | The bare linker binary |
| -Wl,--gc-sections | Drop 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.