Resolving iOS Simulator Issues on Apple Silicon Mac (arm64 Binary Error)

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.

TOC

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.

Solutions

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:

STEP
Open the “Build Settings” tab of the app’s target settings.
STEP
Select “Debug” under “Excluded Architectures” in “Architectures”.
STEP
Click the “+” button in the “Debug” row. “Any SDK” will be added.
Click "+" button
Click “+” button
STEP
Change the added “Any SDK” to “Any iOS Simulator SDK”.
STEP
Enter “arm64” in the “Any iOS Simulator SDK” setting. This will prevent debug builds for the iOS Simulator from building with arm64.
STEP
Do as same as steps (4) and (5) to set arm64 for the “Release” build.
Configure for Release build
Configure for Release build

Authored Books

Let's share this post !

Author of this article

Akira Hayashi (林 晃)のアバター Akira Hayashi (林 晃) Representative(代表), Software Engineer(ソフトウェアエンジニア)

アールケー開発代表。Appleプラットフォーム向けの開発を専門としているソフトウェアエンジニア。ソフトウェアの受託開発、技術書執筆、技術指導・セミナー講師。note, Medium, LinkedIn
-
Representative of RK Kaihatsu. Software Engineer Specializing in Development for the Apple Platform. Specializing in contract software development, technical writing, and serving as a tech workshop lecturer. note, Medium, LinkedIn

TOC