【问题标题】:Activate Build for Any Mac (Apple Silicon, Intel) in old MacOS app [closed]在旧 MacOS 应用程序中激活 Build for Any Mac(Apple Silicon、Intel)[关闭]
【发布时间】:2021-02-13 04:33:40
【问题描述】:

我想将我的 MacApp 移植到一个通用版本,包括新 Apple Silicon Arm64 芯片的二进制文件。

除了在 Xcode 12.1 上使用标准架构构建设置之外,我还需要做什么?我的方案只显示 Any Mac (Intel)

【问题讨论】:

    标签: xcode macos apple-silicon


    【解决方案1】:

    您绝对应该阅读有关此主题的 Apple 官方指南:https://developer.apple.com/documentation/xcode/building_a_universal_macos_binary
    那里很好地介绍了该过程。

    此外,Apple 还提供了一份 Apple Silicon 指南:https://developer.apple.com/documentation/xcode/porting_your_macos_apps_to_apple_silicon
    这也是必读的。

    所以第一步显然是更新架构列表。 当前的 MacMini/Macbook 有x86_64,Apple Silicon 有arm64 等等。

    你应该编译,并一一删除所有编译错误。

    在为 Apple Silicon 构建应用时,我遇到了这样的问题:

    包装特定于平台的代码(此标题复制自 Apple 教程 :))
    例如

    #if os(macOS)
       // Put CPU-independent macOS code here.
       #if arch(arm64)
          // Put 64-bit arm64 Mac code here.
       #elseif arch(x86_64)
          // Put 64-bit x86_64 Mac code here.
       #endif
    #elseif targetEnvironment(macCatalyst)
       // Put Mac Catalyst-specific code here.
    #elseif os(iOS)
       // Put iOS-specific code here.
    #endif
    
    

    构建胖库(这是自定义解释:))
    您的应用程序可以使用任何 C/C++ 静态/动态库,例如 CurlOpenSSL 等。 为了使应用程序通用,您应该确保所有这些库都包含适用于所有平台的代码。 lipo 将成为您的朋友(这也包含在指南中)。 为 Apple Silicon 构建静态库的示例:https://cutecoder.org/programming/compile-open-ssl-apple-silicon/

    我不确定我是否已经完全回答了你的问题,所以请询问更多细节,我会澄清一下。

    【讨论】:

      【解决方案2】:

      Xcode 12.1 没有 macOS 11 SDK,您需要为 Apple Silicon 编译它。在 macOS 11 发布之前,您必须下载包含 macOS 11 SDK 的 Xcode 12 测试版,例如 Xcode 12.2 测试版。

      【讨论】:

      • "Xcode 12.1 没有 macOS 11 SDK" - MacOS Big Sur 上的 Xcode 12 有 :)
      猜你喜欢
      • 1970-01-01
      • 2021-12-06
      • 2021-11-27
      • 2021-08-20
      • 2020-12-09
      • 2021-09-09
      • 2021-03-16
      • 1970-01-01
      • 2018-05-31
      相关资源
      最近更新 更多