Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode12 issus: ld :building for iOS Simulator, but linking in object file built for iOS, file 'xxx.framework/xxx' for architecture arm64

Tags:

xcode

ios

xcode12

After upgrading xcode12,build issus:

ld :building for iOS Simulator, but linking in object file built for iOS, file 'xxx.framework/xxx' for architecture arm64

It can run on iPhone

like image 948
burningsun Avatar asked Sep 17 '20 06:09

burningsun


People also ask

Is iOS simulator arm64?

Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions. Seeing these when trying to create an xcframework for Apple Silicon that supports Mac Catalyst and the iOS Simulator: Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions.

What is build active architecture only?

The "build active architecture only" setting causes everything except the current Mac's architecture to be ignored (and the current one is of course valid), hiding the problem. Instead, you should look up a row or two in the settings, and change the "Architectures" setting to "Standard".

How do I add iOS simulator to Xcode?

Simulator menu -> File -> New Simulator. It will show a list of iOS available for the device. 7.


1 Answers

The Build Settings editor no longer includes the Valid Architectures build setting "VALID ARCHS", and its use is discouraged. Instead, there is a new Excluded Architectures build setting (EXCLUDED ARCHS)

Xcode 12 is actually the stepping stone for Apple Silicon which unfortunately is not yet available. But with that platform, we are gonna get arm64 based macOS where simulators will also run on arm64 architecture unlike the present Intel-based x86_64 architecture.

Xcode usually depends on the "Run Destination" to build its libraries/apps. So when a simulator is chosen as the "Run Destination", it builds the app for available simulator architectures and when a device is chosen as the "Run Destination" it builds for the architecture that the device supports (arm*).

xcodebuild, in the Xcode 12+ build system, considers arm64 as a valid architecture for the simulator. So when a simulator is chosen as the run destination, it can potentially try to compile/link your libs/apps against arm64 based simulators as well (not available yet). So it sends clang(++) some -target flag like arm64-apple-ios13.0-simulator in --- format and clang tries to build/link against arm64 based simulator that eventually fails on Intel-based mac.

But xcodebuild tries this only for Release builds. Why? Because, "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" build settings is usually set to "No" for the "Release" configuration only. And that means xcodebuild will try to build all architectural variants of your libs/apps for the selected run destination for release builds. And for the Simulator run destination, it will includes both x86_64 and arm64 now on, since arm64 in Xcode 12+ is also a supported architecture for simulators to support Apple Silicon.

Simply putting, Xcode will fail to build your app anytime it tries the command line, xcodebuild, (which defaults to release build, see the general tab of your project setting) or otherwise in release mode. So a simple workaround to this issue is to set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes in your libraries/apps, even for release mode.

Select Traget then go to build setting

Steps to resolve the issue :

Solution 1:

  1. Select Project Target
  2. Go to build setting
  3. Select All
  4. search for "Build Active Architecture Only"
  5. Build Active Architecture Only to "Yes" even for release mode.
  6. Build Again

Solution 2:

  1. Select Project Target
  2. Go to build setting
  3. Select All
  4. search for "Excluded Architecture"
  5. Add "arm64" to both Release and Debug mode for the "Any iOS Simulator SDK" option.
  6. Build Again

enter image description here

like image 168
Avneesh Agrawal Avatar answered Oct 13 '22 05:10

Avneesh Agrawal