hippietrail
hippietrail

Reputation: 16974

How to build an Intel binary on an M1 Mac from the command line with the standard Apple version of clang?

I'm playing with some C code on my M1 MacBook Air and looking at the assembly produced with various optimization levels.

I'm building a single C file from the commandline with the most basic command:

cc foo.c -o foo

What switch do I use to build an Intel binary instead of ARM? Are there different flavours of Intel? 32 vs 64 bit? Maybe even older CPU instruction sets? This is surprisingly hard to Google for, but I'm new to the Apple ecosystem.

What about fat binaries? How would I build a single binary that contained both Intel and ARM code from the commandline?

(For the purposes of this question I'm only interested in what I can do on the commandline. If I need to set up XCode projects or environment variables, then I'll accept an answer that just says "You can't do it with just the commandline".)

Upvotes: 10

Views: 10168

Answers (1)

Trev
Trev

Reputation: 658

Intel 32 bit is not executable on macOS since Catalina. Every Mac since 2006, except the original Intel Mac mini with Core Solo processor, is 64 bit capable.

Intel: clang -o myTool-x86_64 -mmacosx-version-min=10.15 -arch x86_64 main.c

ARM64: clang -o myTool-arm64 -mmacosx-version-min=10.15 -arch arm64 main.c

FAT binary: lipo myTool-x86_64 myTool-arm64 -create -output myTool

Upvotes: 18

Related Questions