Specific frameworks incorporated into an application may lead to an error, preventing the iOS simulator from running on an Apple Silicon Mac.
ld: in /Volumes/Data/src/RK/TechGakuWebSite/SampleCodes/OpenCVTest_iOS/common/opencv2.framework/opencv2(ios_conversions.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This error is exemplified in OpenCV 4.6.0. This article provides solutions to resolve this issue.
Cause of the Error
The error seems to arise when an app built with
arm64 for the iOS simulator on an Apple Silicon Mac links the framework for the iOS device to the build for the iOS simulator. This happens when the incorporated framework is not fully compatible with the architecture of Xcode 12 or later or Apple Silicon.
Thanks to Rosetta2 in Apple Silicon Macs, binaries built with the
x86_64 version can still be used in the iOS simulator and Xcode’s SwiftUI preview.
To avoid this issue, adjust the settings when building for the iOS simulator to avoid building with
arm64. Here’s how: