[英]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.我正在 M1 MacBook Air 上使用一些 C 代码,并查看以各种优化级别生成的组件。
I'm building a single C file from the commandline with the most basic command:我正在使用最基本的命令从命令行构建一个 C 文件:
cc foo.c -o foo
What switch do I use to build an Intel binary instead of ARM?我使用什么开关来构建英特尔二进制文件而不是 ARM? Are there different flavours of Intel?
有不同口味的英特尔吗? 32 vs 64 bit?
32 对 64 位? Maybe even older CPU instruction sets?
也许甚至更旧的 CPU 指令集? 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?
如何从命令行构建包含 Intel 和 ARM 代码的单个二进制文件?
(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".) (出于这个问题的目的,我只对我可以在命令行上执行的操作感兴趣。如果我需要设置 XCode 项目或环境变量,那么我会接受一个答案,只是说“你不能这样做仅使用命令行”。)
Intel 32 bit is not executable on macOS since Catalina.自 Catalina 以来,英特尔 32 位无法在 macOS 上执行。 Every Mac since 2006, except the original Intel Mac mini with Core Solo processor, is 64 bit capable.
自 2006 年以来的每台 Mac,除了最初的配备 Core Solo 处理器的 Intel Mac mini 外,都支持 64 位。
Intel: clang -o myTool-x86_64 -mmacosx-version-min=10.15 -arch x86_64 main.c
英特尔:
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
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
FAT 二进制文件:
lipo myTool-x86_64 myTool-arm64 -create -output myTool
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.