How do I change the default rustc / Cargo linker?

前端 未结 1 757
小鲜肉
小鲜肉 2021-01-17 17:39

I would like to make rustc use lld as a linker instead of ld in a particular crate. So I create .cargo/config in my project directory

1条回答
  •  伪装坚强ぢ
    2021-01-17 18:18

    Thanks to @Jmb comment, I found a solution. Turns out that the default linker that rustc uses is actually cc (which makes sense - it supplies all the needed defaults to compile/link C code, which also work for Rust). We can pass an argument to cc to make it link with lld:

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

    Now cargo build links with lld.

    0 讨论(0)
提交回复
热议问题