Skip to content

Instantly share code, notes, and snippets.

@mlabbe
Created December 11, 2020 23:08
Show Gist options
  • Save mlabbe/2371c36ba405fe5af91f2d94cc8151e5 to your computer and use it in GitHub Desktop.
Save mlabbe/2371c36ba405fe5af91f2d94cc8151e5 to your computer and use it in GitHub Desktop.
MacOS M1 cross compile and build a fat binary with aarch64/arm64 and x86_64/amd64
#!/bin/bash
clang hello.c -target arm64-apple-darwin20.1.0 -o hello.arm64
echo -n "hello.arm64 is architecture " && lipo -archs ./hello.arm64
clang hello.c -target x86_64-apple-darwin-macho -o hello.x86_64
echo -n "hello.x86_64 is architecture " && lipo -archs ./hello.x86_64
lipo hello.arm64 hello.x86_64 -create -output hello
echo -n "final output binary has archs " && lipo -archs ./hello
#include <stdio.h>
int main(void) {
puts("Hello, world!");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment