从 Windows 到 ARM Linux 的交叉编译 Rust [英] Cross-compiling Rust from Windows to ARM Linux

查看:52
本文介绍了从 Windows 到 ARM Linux 的交叉编译 Rust的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 10.我想交叉编译一个 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.)

这是我的步骤:

  1. 安装rustup
  2. rustup 工具链安装 stable-x86_64-pc-windows-gnu
  3. rustup 工具链默认 stable-x86_64-pc-windows-gnu
  4. rustup 目标添加 armv7-unknown-linux-gnueabihf
  5. 编辑我的 ./cargo/config 文件以包含:

[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 没有自己的链接器,而是使用 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 并获得实际可移植的二进制文件(即它不依赖于经常导致兼容性问题的 GNU C 库).

    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 到 ARM Linux 的交叉编译 Rust的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆