rust windows 交叉编译,从Windows交叉编译Rust到ARM Linux

I'm using Windows 10. I would like to cross-compile a Rust program to run on armv7-unknown-linux-gnueabihf. (armv7-unknown-linux-muscl would also be acceptable but it doesn't seem to be available.)

Here are my steps:

Install rustup

rustup toolchain install stable-x86_64-pc-windows-gnu

rustup toolchain default stable-x86_64-pc-windows-gnu

rustup target add armv7-unknown-linux-gnueabihf

Edit my ./cargo/config file to contain:

[build]

target = "armv7-unknown-linux-gnueabihf"

cargo build

This compiles everything fine, but when it comes to linking it gives this error:

error: could not exec the linker `cc`: The system cannot find the file specified. (os error 2)

As far as I have been able to determine, this is because Rust doesn't have its own linker and uses GCC instead. Apparently I need to provide this myself and add this to the ./cargo/config file:

[target.armv7-unknown-linux-gnueabihf]

linker = "c:/path/to/my/gcc/cross/compiler"

Is that right? If so where on Earth can I download such a cross-compiler for Windows and why doesn't rustup install it? Having to compile a cross-compiling version of GCC yourself is the biggest pain of cross-compiling C/C++ programs. Does Rustup really not make this any easier?

解决方案

Thanks to @Notlikethat's comment:

a) Yes you need to provide your own GCC cross-compiler.

b) You can get one here (select a mingw32 build).

Just unzip linaro's GCC then point cargo to it:

[target.armv7-unknown-linux-gnueabihf]

linker = "C:/Users/me/gcc-linaro-5.3.1-2016.05-i686-mingw32_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe"

It seems to work even though it is arm- and not armv7-. I guess linking doesn't depend on the ISA. Actually I haven't run it yet, but it builds without errors!

Edit:

You can now use armv7-unknown-linux-musleabihf instead and get an actually portable binary (i.e. it doesn't depend on the GNU C library which often causes compatibility issues).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值