Unable to execute binary in Amazon Linux 2 AMI

Unable to execute binary in Amazon Linux 2 AMI

What is the error?

-bash: ./test: cannot execute binary file

What do uname -a and file ./test show?

uname -a : x86_64 x86_64 x86_64 GNU/Linux
file ./test : ./test: Mach-O 64-bit executable

Looks like you have an executable compiled for macOS. Linux can't run macOS executables. You will need to compile it for Linux instead. I'm assuming you are using macOS on your own computer. If so there are three options you have:

  • Compile your program in the AWS VM
  • Compile your program locally in a Linux VM (eg using docker)
  • Cross-compile to Linux with musl libc by doing rustup target add x86_64-unknown-linux-musl once and then add --target x86_64-unknown-linux-musl to future cargo build commands. The executable will then be placed in target/x86_64-unknown-linux-musl/debug or target/x86_64-unknown-linux-musl/release depending on if you enabled release mode or not.

Thanks for the reply. I will check and let you know.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.