Xcode 12 - Architecture

3,330 阅读1分钟

一、building for iOS Simulator, but linking in object file built for iOS, xxxx for architecture arm64

原项目迁移到 Xcode 12 运行模拟器的时候出现报错,在真机可正常运行

  • 在 Xcode 11 中,我们通过 Build Setting -> Architectures -> Valid Architectures 中填写支持的指令集
  • 在 Xcode 12 中,Valid Architectures 这一项被移除掉了,替换成 User-Defined 中的 VALID_ARCHS

区别在于 Xcode 11 中 x86_64 是默认添加的,就算不填写也是默认支持,但是在 Xcode 12 中默认不添加 x86_64,需要手动加入

二、 in XXX.a(XXXXXXX.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

静态库工程编译模拟器库报错,该提示说明该库不支持模拟器 arm64,需要在 Build Setting -> Excluded Architectures 添加 Any iOS Simulator SDK 对应值为 arm64

三、have the same architectures (arm64) and can't be in the same fat output file

Xcode 12 之前

  • 编译模拟器静态库支持 i386x86_64 两个架构
  • 编译真机静态库支持 armv7arm64 两个架构
  • 我们一般将 lib -create -output 命令将两个库合并成一个,支持四种架构的库

Xcode 12 编译的模拟器静态库新增支持 arm64,导致和真机静态库不能合并的问题

需要忽略掉模拟器编译的 arm64,在 Build Setting -> Excluded Architectures 添加 Any iOS Simulator SDK 对应的值为 arm64

针对已打包好的 .a 或 .framework lipo XXX.a -remove arm64 -output XXX.a

四、The linked library 'xxxx.a/Framework' is missing one or more architectures required by this target: armv7.

Target -> Build Setting -> Exculded Architectures 中添加如下代码

EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))