Cannot find 'ld' when using 'lld'

In an attempt to speed up linking I am trying to use the lld linker.

I have edited my .cargo/conf file to contain the following:

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-args=-rdynamic", "-C", "link-arg=-fuse-ld=lld"]

I have llvm installed, although possibly relevant on Ubuntu it has installed lld as lld-10. I have symlinked /usr/bin/lld -> usr/bin/lld-10 just to make sure.

ld exists in /usr/bin/ld

However when I try to cargo build I get the error:

  = note: collect2: fatal error: cannot find ‘ld’
          compilation terminated.

Any ideas why?

You choose linkers not by overriding the ld command but choosing to run ld.bfd, ld.gold, ld.lld, etc.

It's the bit after the dot in ld.xyz that you specify in -fuse-ld=xyz. So just make sure that /usr/bin/ld.lld points to your linker and should be good. Something like

ln -s /usr/bin/ld.lld-* /usr/bin/ld.lld
2 Likes

Ah! Ok that seems to have done it. Many thanks!

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.