如何在AWS EC2实例上运行MacOS上的Rust? “不能执行二进制文件:Exec格式错误;

发布于 2025-02-09 04:02:35 字数 676 浏览 2 评论 0原文

问题

我已经在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琴流音 2025-02-16 04:02:36

我发现做类似事情的最简单方法是使用 cross 。这是一种货物扩展,将拉动交叉编译到其他建筑所需的所有依赖项。命令格式与货物有意

cross build --release --target aarch64-unknown-linux-gnu

相同 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.

cross build --release --target aarch64-unknown-linux-gnu

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.

过期以后 2025-02-16 04:02:36

看来目标架构不是基于ARM的。AMD应该需要X86_64目标。

it looks like the target architecture is not arm-based.. AMD should require an x86_64 target.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文