How do I explicitly use the default Rust linker?

I've set up mold as my default linker in $HOME/.cargo/config.toml

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]

How do I fall back to the default Rust linter for a single project?

I've tried setting linker = "" / "clang" / "gcc" / "ld" / "ldd" and rustflags = [], but no combination seems to works.

1 Like

I think this is a deficiency in Cargo's ability to configure the linker:

because Cargo doesn't understand rustflags content and can't undo the selection made there.


You'd have to ensure the rustflags are replaced instead of merged. Setting RUSTFLAGS env var may do the trick, but it will also replace flags from other layers of the configuration.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.