Why does my native arm64 application built using an x86_64 build system report "killed" when executed on Apple Silicon?

  apple-silicon, c++, macos, native

I have a simple C application:

#include <stdio.h>

int main() {
  printf("Hello, world!n");

When I build this on an Apple Silicon device, targeting arm64, but using a build system that is compiled for x86_64, the final binary cannot be executed and is reported as "killed" according to the shell:

# arch simulates the build system which is still compiled for x86_64
% arch -x86_64 cc -arch arm64 hello.c -o hello

% file hello
hello: Mach-O 64-bit executable arm64

% ./hello
zsh: killed     ./hello

Even attempting to debug it fails:

% lldb hello
(lldb) target create "hello"
zsh: killed     lldb hello

As a workaround, I can use a shim compiler to "reset" back to an arm64 environment before calling cc, but that’s inelegant and it feels like I’m missing some configuration to avoid jumping through so many hoops.

Source: Windows Questions C++