我想让rustc使用lld
作为链接器,而不是在特定的 crate 中使用ld
.因此,我在我的项目目录中创建.cargo/config
,如下所示:
[target.x86_64-unknown-linux-gnu]
linker = "ld.lld"
这会导致链接器错误:
$ cargo build
...
= note: ld.lld: error: unable to find library -ldl
ld.lld: error: unable to find library -lrt
ld.lld: error: unable to find library -lpthread
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lm
ld.lld: error: unable to find library -lrt
ld.lld: error: unable to find library -lpthread
ld.lld: error: unable to find library -lutil
ld.lld: error: unable to find library -lutil
rust-lld
也一样.如果我设置linker = "ld"
(这应该是默认值,对吗?),我只是
= note: ld: cannot find -lgcc_s
我试图手动解析所有缺失的库(-C link-arg=--library-path=/usr/lib/x86_64-linux-gnu
个之类),但这只会导致错误的链接和错误的二进制文件.
有趣的是,如果我将/usr/bin/ld
替换为/usr/bin/ld.lld
的符号链接,它的效果非常好(没有错误,从编译的二进制文件中我看到它确实与lld
链接).然而,我不想让lld
成为我的系统级链接器,我只想把它用在一个特殊的Rust 的 crate 中.
那么,更改默认rustc链接器的正确方法是什么?