Xcode11 无法识别静态库架构:Mac Catalyst(又名 UIKit For Mac)

Xcode 11 not recognizing static library's architecture: MacCatalyst (aka UIKitForMac)

在对 2019 年的 WWDC 公告感到兴奋之后,我尝试使用 Xcode 11.0 beta 针对 MacOS 编译我现有的 iOS 应用程序。不幸的是,它没有按预期进行。

Xcode 说我的静态库是为<未知>架构构建的:

Building for UIKit for Mac, but the linked library 'libssl.a' was built for < unknown >. You may need to restrict the platforms for which this library should be linked in the target editor.

但是当我检查我的静态库时,我可以看到它们确实包含所需的架构 x86_64

我认为此问题可能与 Xcode Beta 错误有关。有人对此有想法吗?

One-line修复:

git clone git@github.com:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7"

解释:

根据 Apple 软件工程师 edford 的说法,我们需要为 iOS 平台构建二进制文件,目标 MacOSX 并使用 CFLAG -target x86_64-apple-ios13.0-macabi。这里有一个非常有启发性的讨论:https://forums.developer.apple.com/message/362577.

我已经 fork OpenSSL-for-iPhone here 并在分支 feature/mac-catalyst 中实现了 MacCatalyst 支持。

您可以通过指定 archstargets:

MacCatalyst 构建它

选项 --archs,对于 OpenSSL <= 1.0.2:

git clone git@github.com:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7"  --version="1.0.2l"

OpenSSL 选项 --targets >= 1.1.0

git clone git@github.com:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --targets="ios-sim-cross-i386 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 mac-catalyst-x86_64" --version="1.1.0"

以上所有解决方案都不适合我,所以我继续尝试为我的系统修复它 运行 Mac OSX 10.15.4。

就我而言,这是上述解决方案对我不起作用的地方:

no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.4.sdk' [-Wmissing-sysroot]

我通读了 build-libssl.sh 文件,注意到 sdk 版本是由脚本使用以下代码获取的:

xcrun -sdk macosx --show-sdk-version

在我的系统上 return:

10.15.4

使用 finder 导航到该位置:

'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

确实告诉我确实没有 MacOSX10.15.4.sdk。然而,有一个MacOSX10.14.sdk。我确实利用这些知识提出了以下解决方案:

OpenSSL 版本 <= 1.0 (1.0.2l)

versions <= 1.0 should only use --arch, not --target !

git clone git@github.com:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --arch="MacOSX_x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64" --macosx-sdk=10.15 --version="1.0.2l"

OpenSSL 版本 >= 1.1 (1.1.0) 目前无法使用

versions >= 1.1 should only use --target, not --arch !

git clone git@github.com:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --targets="mac-catalyst-x86_64 ios-sim-cross-i386 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 tvos-sim-cross-x86_64 tvos64-cross-arm64" --macosx-sdk=10.15 --version="1.1.0" -v