如何在AWS EC2实例上运行MacOS上的Rust? “不能执行二进制文件:Exec格式错误;
问题
我已经在MacBook上写了一些相当简单的生锈代码,要在AWS EC2实例上部署,但是当我将二进制二进制并运行它时,我会遇到“ bash-- program-cannot-execute-binary-file-exec-format-error “
mac详细信息
- productname:macos
- productersion:12.4
- 构建器:21f79
aws aws详细信息详细信息
- 实例类型: T3.Micro
UNAME -R
:5.10.0-10-cloud-amd64
尝试的解决方案
我知道,这是我的机器架构与EC2机器的架构之间的不匹配,因为EC2是Debian,我认为我想要的目标类型是“ Aarch64-Inknown-linux-gnu”,但是运行货物构建-target = aarch64-inarch64-inknown-innown-innown-linux-gnu
“错误:与cc
链接失败:退出状态:1 “很长的音符。
Problem
I've written some fairly simple Rust code on a Macbook, to be deployed on an AWS EC2 instance but when I SCP the binary across and run it, I am met with "bash-program-cannot-execute-binary-file-exec-format-error"
Mac Details
- ProductName: macOS
- ProductVersion: 12.4
- BuildVersion: 21F79
AWS Details
- Instance type: t3.micro
uname -r
: 5.10.0-10-cloud-amd64
Attempted Solution
I understand that it's a mismatch between the architecture of my machine vs the EC2 machine and since the EC2 is Debian, I'm assumed that the target type I want is "aarch64-unknown-linux-gnu", but running cargo build --target=aarch64-unknown-linux-gnu
results in "error: linking with cc
failed: exit status: 1
" with a very lengthy note.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现做类似事情的最简单方法是使用 cross 。这是一种货物扩展,将拉动交叉编译到其他建筑所需的所有依赖项。命令格式与货物有意
:
相同 https://github.com/cross-rs/cross#installation
对于实际错误,我相信仅设置目标的问题是Rust仍然取决于已安装的LIBC,这将适用于本机架构。
Cross
使用Docker Images将其围绕。The easiest way I've found to do a similar thing is use cross. This is a cargo extension that will pull in all the dependencies needed to cross compile onto a different architecture. The command format is deliberately identical to cargo:
e.g.
You can find instructions to set it up on their wiki page: https://github.com/cross-rs/cross#installation
As for the actual error, I believe the problem with just setting the target in cargo is that rust will still depend on the installed libc which will be for the native architecture.
cross
gets round this by using docker images.看来目标架构不是基于ARM的。AMD应该需要X86_64目标。
it looks like the target architecture is not arm-based.. AMD should require an x86_64 target.