简体   繁体   English

在 Intel 机器上为不同的 macOS 版本构建 Apple Silicon M1 二进制文件

[英]Build Apple Silicon M1 binary on an Intel machine for different macOS versions

I'm looking for a way to compile a C++ project to work on M1 with different macOS versions (both macOS 11 and 12).我正在寻找一种方法来编译 C++ 项目以在具有不同 macOS 版本(macOS 11 和 12)的 M1 上工作。

I looked at this question: Build Apple Silicon binary on Intel machine我看了这个问题: Build Apple Silicon binary on Intel machine

And it suggests using:它建议使用:

-target arm64-apple-macos11

It works well for macOS 11 but doesn't work for macOS 12. For macOS 12 there are other targets:它适用于 macOS 11,但不适用于 macOS 12。对于 macOS 12,还有其他目标:

-target arm64-apple-macos12

-target arm64-apple-macos12.3

Is there a generic -target I can use that will work for all macOS versions (maybe even future versions)?是否有一个通用的-target我可以使用它适用于所有 macOS 版本(甚至可能是未来版本)?

Actually, Xcode is a pretty good C++ compiler.实际上,Xcode 是一个相当不错的 C++ 编译器。 If you use Xcode to build C++, to build a universal binary.如果使用 Xcode 构建 C++,构建通用二进制。 You will find Xcode has below steps when building(remember to set "NO" to Build Active Architecture Only in build settings):您会发现 Xcode 在构建时有以下步骤(请记住在构建设置中将“NO”设置为仅构建活动架构): 在此处输入图像描述 It first compiles and link for x86_64 and then arm64, and finally uses lipo to create a universal binary.它首先为 x86_64 和 arm64 编译和链接,最后使用lipo创建一个通用二进制文件。

So you can create a demo c++ code and inspect the build reports to check what command xcode is using to compile your project(by collapsing the menu icon on the right side).因此,您可以创建一个演示 c++ 代码并检查构建报告以检查 xcode 使用什么命令来编译您的项目(通过折叠右侧的菜单图标)。

So get back to your question:所以回到你的问题:

Is there a generic -target I can use that will work for all macOS versions (maybe even future versions)?是否有一个通用的 -target 我可以使用它适用于所有 macOS 版本(甚至可能是未来版本)?

Yes.是的。 For example, if you are targeting macos 11, you can use -target x86_64-apple-macos11.0 for intel CPUs and arm64-apple-macos11.0 for apple silicon CPUs.例如,如果您的目标是 macos 11,则可以将-target x86_64-apple-macos11.0用于英特尔 CPU, arm64-apple-macos11.0用于苹果硅 CPU。 By default, targeting macos 11 means you can run the binary in future macos version.默认情况下,以 macOS 11 为目标意味着您可以在未来的 macOS 版本中运行二进制文件。

If you have any questions leave a comment below.如果您有任何问题,请在下面发表评论。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apple Silicon M1 Pro 上的 MPI 和 OpenMP - MPI and OpenMP on Apple Silicon M1 Pro 链接英特尔库以在 M1 Mac 上使用 Xcode 生成英特尔二进制文件 - Link Intel Library to Generate Intel Binary on M1 Mac with Xcode 在 Apple M1 (arm) 上使用 cmake 为 macOS-x86_64 构建的正确方法是什么? - What is the proper way to build for macOS-x86_64 using cmake on Apple M1 (arm)? 在 Apple Silicon M1 上激活并绑定了 GL_TEXTUREn+1 而不是 GL_TEXTUREn(可能的错误) - GL_TEXTUREn+1 activated and bound instead of GL_TEXTUREn on Apple Silicon M1 (possible bug) MacOS Big Sur M1 芯片,R devtool monocle3 安装过程中出现 cmath 错误 - MacOS Big Sur M1 silicon, cmath error during R devtool monocle3 install Apple Silicon M1/Clion IDE 在旧项目上运行非常缓慢,但在新创建的项目上运行良好。 为什么? - Apple Silicon M1/Clion IDE runs really slow on old projects but runs well on newly created. Why? 将 boost 编译为通用库(Intel 和 Apple Silicon 架构) - Compile boost as universal library (Intel and Apple Silicon architectures) 类型转换(下溢?)英特尔与 M1 的差异 - Typecasting (underflow?) differences intel vs M1 C++/C 代码在 M1 和 Intel 上有不同的执行块 - C++/C Code to have different execution block on M1 and Intel 如何为英特尔和 arm 架构构建具有不同代码的 osx 通用二进制文件 - How to build an osx universal binary with different code for intel and arm architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM