mold "-fuse-ld=mold not found" / cannot find mold in CI
The build asked the compiler to link with mold via -fuse-ld=mold, but mold is not on the runner, or the compiler predates -fuse-ld=mold support and cannot resolve it. The link step fails before producing a binary.
What this error means
Linking fails with "collect2: fatal error: cannot find \"mold\"", "unknown argument: -fuse-ld=mold", or "-fuse-ld=mold: not found".
collect2: fatal error: cannot find 'mold'
compilation terminated.Common causes
mold is not installed on the runner
The compiler flag names mold but the binary is absent, so the driver cannot invoke the linker.
The compiler is too old for -fuse-ld=mold
Older gcc/clang do not accept -fuse-ld=mold by name; they need a path or the mold -run wrapper instead.
How to fix it
Install mold and use a supported invocation
- Install mold from the package manager or a release.
- On newer gcc/clang, pass
-fuse-ld=mold. - On older compilers, use
mold -runor point at the mold path.
sudo apt-get update && sudo apt-get install -y mold
# newer toolchains
export LDFLAGS="-fuse-ld=mold"
# older toolchains
mold -run cmake --build buildSet the mold path explicitly
When the name is not recognized, point the driver at the mold binary directly.
export LDFLAGS="-fuse-ld=/usr/bin/mold"How to prevent it
- Install mold in a setup step before any link that requests it.
- Match the invocation form to the compiler version.
- Bake mold into custom images used for link-heavy builds.