方法一
树莓派Zero 用的 BCM2835 是 armv6 架构的。arm-linux-gnueabihf-gcc
pacaur -S arm-linux-gnueabihf-gcc
rustup target add arm-unknown-linux-gnueabihf
Cargo 设置
需要给 cargo 的配置文件里面指定 arm-unknown-linux-gnueabihf 的 linker.
默认配置一般在 ~/.cargo/config 这里, 没有就创一个.
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
来告诉 cargo 在编译到 arm-unknown-linux-gnueabihf target 的时候用之前安装的 gcc 做 linker, 不然会默认用 cc 做 linker, 那这当然是不行的.
测试
cargo build --target=arm-unknown-linux-gnueabihf
用scp传到树莓派上就可以了
方法二
用cross,非常方便,强烈推荐!!!
# (ONCE PER BOOT)
# Start the Docker daemon, if it's not already running
sudo systemctl start docker
# MAGIC! This Just Works
#cross build --target arm-unknown-linux-musleabihf
cross build --target arm-unknown-linux-gnueabihf
# EVEN MORE MAGICAL! This also Just Works
cross test --target mips64-unknown-linux-gnuabi64
# Obviously, this also Just Works
cross rustc --target powerpc-unknown-linux-gnu --release -- -C lto