Tim*_*mmm 5 windows gcc arm cross-compiling rust
我正在使用Windows10。我想交叉编译一个Rust程序以在上运行armv7-unknown-linux-gnueabihf。(armv7-unknown-linux-muscl也可以接受,但似乎不可用。)
这是我的步骤:
rustuprustup toolchain install stable-x86_64-pc-windows-gnurustup toolchain default stable-x86_64-pc-windows-gnurustup target add armv7-unknown-linux-gnueabihf编辑我的./cargo/config文件以包含:
[build]
target = "armv7-unknown-linux-gnueabihf"
Run Code Online (Sandbox Code Playgroud)cargo build
这样可以很好地进行编译,但是在进行链接时会出现以下错误:
[build]
target = "armv7-unknown-linux-gnueabihf"
Run Code Online (Sandbox Code Playgroud)
据我所能确定的,这是因为Rust没有自己的链接器,而是使用GCC。显然,我需要自己提供并将其添加到./cargo/config文件中:
[target.armv7-unknown-linux-gnueabihf]
linker = "c:/path/to/my/gcc/cross/compiler"
Run Code Online (Sandbox Code Playgroud)
那正确吗?如果是这样,我可以在地球上的哪个地方下载用于Windows的交叉编译器,为什么不rustup安装它呢?不得不自己编译GCC的交叉编译版本是交叉编译C / C ++程序的最大痛苦。Rustup真的不会使这变得容易吗?
感谢@Notlikethat 的评论:
a) 是的,您需要提供自己的 GCC 交叉编译器。
b) 你可以在这里得到一个(选择一个mingw32版本)。
只需解压缩 linaro 的 GCC,然后将货物指向它:
[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"
Run Code Online (Sandbox Code Playgroud)
即使它是arm-和不是,它似乎也能工作armv7-。我想链接不依赖于 ISA。实际上我还没有运行它,但它构建没有错误!
编辑:
您现在可以armv7-unknown-linux-musleabihf改用并获得一个实际可移植的二进制文件(即它不依赖于经常导致兼容性问题的 GNU C 库)。
对于 MacOS 更好地使用:musleabihf,对于 Windows 您可以使用gnueabihf如下:
苹果
$ brew install arm-linux-gnueabihf-binutils
$ rustup target add armv7-unknown-linux-musleabihf
Run Code Online (Sandbox Code Playgroud)
在.cargo/config
[build]
target = "armv7-unknown-linux-musleabihf"
[target.armv7-unknown-linux-c]
linker = "arm-linux-gnueabihf-ld"
Run Code Online (Sandbox Code Playgroud)
用简单的src/main.rs
[build]
target = "armv7-unknown-linux-musleabihf"
[target.armv7-unknown-linux-c]
linker = "arm-linux-gnueabihf-ld"
Run Code Online (Sandbox Code Playgroud)
那么事情就很好了:
fn main() {
println!("Hello, Raspberry!");
}
Run Code Online (Sandbox Code Playgroud)
Win 10从这里 获取链接器,然后运行:
Hasans-Air:rpi hasan$ cargo build
Compiling rpi v0.1.0 (/Users/hasan/PycharmProjects/rpi)
Finished dev [unoptimized + debuginfo] target(s) in 0.41s
Hasans-Air:rpi hasan$ scp target/armv7-unknown-linux-musleabihf/debug/rpi pi@192.168.1.43:
pi@192.168.1.43's password:
rpi 100% 2702KB 2.6MB/s 00:01
Hasans-Air:rpi hasan$ ssh pi@192.168.1.43 'chmod +x ~/rpi && ~/rpi'
pi@192.168.1.43's password:
Hello, Raspberry!
Run Code Online (Sandbox Code Playgroud)
创建 .cargo/config 包含内容的文件:
[build]
target = "armv7-unknown-linux-gnueabihf"
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
Run Code Online (Sandbox Code Playgroud)
并用简单的src/main.rs:
rustup target add armv7-unknown-linux-gnueabihf
Run Code Online (Sandbox Code Playgroud)
我能够把事情做好
| 归档时间: |
|
| 查看次数: |
3396 次 |
| 最近记录: |