从Windows交叉编译Rust到ARM Linux [英] Cross-compiling Rust from Windows to ARM Linux
问题描述
我正在使用Windows10。我想交叉编译一个Rust程序,使其在 armv7-unknown-linux-gnueabihf
上运行。 ( armv7-unknown-linux-muscl
也可以接受,但似乎不可用。)
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.)
这是我的步骤:
- 安装
rustup
-
rustup工具链安装稳定-x86_64-pc-windows-gnu
-
rustup工具链默认稳定-x86_64-pc-windows-gnu
-
rustup目标添加armv7-unknown-linux-gnueabihf
-
编辑我的
./ cargo / config
文件以包含:
- 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"
货物建造
这可以编译一切正常,但是在链接时会出现此错误:
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)
据我所能确定,这是因为Rust不会t有其自己的链接器,而是使用GCC。显然,我需要自己提供并将其添加到 ./ cargo / config
文件中:
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"
是吗?如果是这样,我可以在Windows的哪里下载这样的交叉编译器,为什么 rustup
不安装它?不得不自己编译GCC的交叉编译版本是交叉编译C / C ++程序的最大痛苦。 Rustup真的不会使它变得更简单吗?
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?
推荐答案
感谢@Notlikethat的注释:
Thanks to @Notlikethat's comment:
a)是,您需要提供自己的GCC交叉编译器。
a) Yes you need to provide your own GCC cross-compiler.
b)您可以获得一个此处(选择 mingw32
b) You can get one here (select a mingw32
build).
只需解压缩linaro的GCC,然后将货物指向它:
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"
即使它是,它似乎也能正常工作arm-
而不是 armv7-
。我想链接不取决于ISA。其实我还没有运行它,但是它的构建没有错误!
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!
编辑:
您现在可以使用 armv7-unknown-linux-musleabihf
来获取实际可移植的二进制文件(即,它不依赖于经常导致兼容性问题)。
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).
这篇关于从Windows交叉编译Rust到ARM Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!