XCode 构建错误 - 缺少所需的模块“算法”

问题描述

背景

  1. 我试图将旧项目从 xcode 11.3 升级到 xcode 12.4。代码仍在 Swift 4.2 上
  2. 当尝试构建(任何 iOS 设备 - arm64)时,项目中的每个 swift 文件都出现相同的错误
 <unkNown\>:0: error: missing required module '**Algorithms**'

3. 尝试使用 xcode 11.3 重建后,我发现 arm64-apple-ios.swiftinterface 实际上是在文件顶部添加 import 'Algorithms' {{ 0}}

//swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift 版本 5.3.1 (swiftlang-1200.8.41 clang-1200.0.32.8)
// swift-module-flags: -target arm64-apple-ios9.0 -enable-objc-interop -enable-librar -swift-version 5 -enforce-exclusivi 检查 -Onone -module-name Charts
导入算法
@_exported 导入图表
导入核心图形

问题

  • 如何将这个algorithms.h添加到项目/编译过程中,使项目能够编译?

  • 是什么导致编译器添加了这个?是不是因为构建设置 > Swift Language Version > Swift 4.2 ?

我尝试了什么

  • 重新安装 XCode 命令行工具 12.4
  • Build Settings->Apple Clang - Language-C++ ->C++ Standard Library(libc++) 参考:[https://stackoverflow.com/questions/25649385/algorithm-file-not-found]

解决方法

问题现已解决。

我们正在使用的库之一似乎依赖于新的“算法”Swift ( https://github.com/apple/swift-algorithms ) 。因此我们可以通过两种方式解决

  • 向项目添加 Algorithms Swift 依赖项
  • 在使用 Algorithms Swift 之前将库恢复到

谢谢。