Win10子系统(WSL2) 安装Rust及问题解决(系统源与source.list不一致, /usr/bin/ld: cannot find crti.o)

762 阅读1分钟

wsl安装rust

打开官网可以看到, 官方给出了脚本, 直接复制执行即可

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

我已经安装过了, 所以打印出了我的rust信息, 未安装的直接选择圈中的默认安装(回车直接执行)即可.

看到rustc/cargo都能打印就是安装好了

新建项目

cargo new hello

项目启动

cargo r

我在此处碰到了错误/usr/bin/ld: cannot find crti.o: No such file or directory

错误处理

执行编译时error: linking with cc failed: exit code: 1

...... [ /usr/bin/ld: cannot find crti.o: No such file or directory]

该错误是因为缺少libc6-dev

sudo apt install -y libc6-dev

执行时可能发生依赖版本太高/低的的错误, 检查自己的source.list源文件和自己的系统版本是否能对上

codename要和源的codename对应, 否则系统依赖会出问题, 修改完source.list之后

sudo apt update && sudo apt upgrade

自动安装好了libc6-dev, 大功告成, hello world!