skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. it looks like the target architecture is not arm-based.. AMD should require an x86_64 target.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search