Clang 编译 Apple 全平台的 triple 和 sysroot 配置

May 04, 2024 • 预计阅读时间 1 分钟

Apple 平台上采用的是 Fat 模式的编译方式,就是编译的目标可以同时包含多种不同的架构,比如 macOS 上就可以同时包含 3 种架构: i386, x86_64 和 arm64。

Apple 平台的另一个编译特点就是可以指定最低系统版本,比如在编译时可以指定 macOS 最低的系统要求是 10.15。

Apple 平台的官方编译器是 Clang,包含在开发工具 Xcode 中,也可以只安装 Command Line Tools 来获得,如果需要编译 iOS、tvOS、watchOS 和 visionOS 那么安装 Xcode 就是必须的。

安装了 Xcode 或者 Command Line Tools 以后,需要使用 xcrun 找到工具链的位置,这样才能保证编译时能正确的链接到对应系统的 SDK。

Apple 已经放弃了 32 位的支持,所以也不需要编译 i386、 armv7 和 armv7k 的代码了。

仅支持运行 64 位代码的系统:macOS 10.14+, iOS 11+, tvOS 9.0+, watchOS 9.0+

OSTripleArchssysroot
macOS-target apple-macosx10.9-arch x86_64 -arch arm64-isysroot xcrun --sdk macosx --show-sdk-path
macCatalyst-target apple-ios13.1-macabi-arch x86_64 -arch arm64-isysroot xcrun --sdk macosx --show-sdk-path
iOS-target apple-ios11.0-arch arm64-isysroot xcrun --sdk iphoneos --show-sdk-path
iOS Simulator-target apple-ios11.0-simulator-arch x86_64 -arch arm64-isysroot xcrun --sdk iphonesimulator --show-sdk-path
tvOS-target apple-tvos9.0-arch arm64-isysroot xcrun --sdk appletvos --show-sdk-path
tvOS Simulator-target apple-tvos9.0-simulator-arch x86_64 -arch arm64-isysroot xcrun --sdk appletvsimulator --show-sdk-path
watchOS-target apple-watchos9.0-arch arm64-isysroot xcrun --sdk watchos --show-sdk-path
watchOS Simulator-target apple-watchos9.0-simulator-arch x86_64 -arch arm64-isysroot xcrun --sdk watchsimulator --show-sdk-path
visionOS-target apple-xros1.0-arch arm64-isysroot xcrun --sdk xros --show-sdk-path
visionOS Simulator-target apple-xros1.0-simulator-arch x86_64 -arch arm64-isysroot xcrun --sdk xrsimulator --show-sdk-path
clang
版权声明:如果转发请带上本文链接和注明来源。

lvv.me

iOS/macOS Developer

解决 macOS 上运行 App 提示「已损坏」的问题