简体   繁体   English

如何使用标准 Apple 版本的 clang 从命令行在 M1 Mac 上构建 Intel 二进制文件?

[英]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.

相关问题 运行使用 Apple M1 芯片(基于 ARM 的系统)构建的容器时出现“exec 格式错误” - "exec format error" when running containers build with Apple M1 Chip (ARM based systems) 如何在 Mac M1 上安装 Google Cloud DLP? - How to install Google Cloud DLP on Mac M1? 如何使用 zsh 在 Mac M1 上安装 gke-gcloud-auth-plugin - How do I install gke-gcloud-auth-plugin on a Mac M1 with zsh Cocoapods M1 Mac 中Flutter 项目报错 - Cocoapods Error in Flutter Project in M1 Mac 在 Intel Mac 上构建或运行 Mac Catalyst 应用程序? - Build or run Mac Catalyst apps on Intel Mac? 如何从 mac 上的程序集中获取对标准输入的引用? - How can I get a reference to standard input from assembly on a mac? 如何为基于 Intel 的最新 Mac OS 创建具有特定/仅本机架构的存档构建 - How to create Archive build with Specific / Native Only Architecture for Intel based Latest Mac OS 如何在 m1 上安装 x86/64 架构 pod - How to install x86/64 architecture pod on m1 Pip 在 Mac OS 上安装出现错误:命令“/usr/bin/clang”失败,退出代码为 1 - Pip install on Mac OS gets error: command '/usr/bin/clang' failed with exit code 1 在 Mac M1 上使用节点 Canvas 部署 Firebase Cloud-Function 失败 - Deploy Firebase Cloud-Function with Node Canvas fails on Mac M1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM