# Link error with OpenCV from Swift on M1 Mac building for iOS simulator

**URL:** <https://forum.opencv.org/t/link-error-with-opencv-from-swift-on-m1-mac-building-for-ios-simulator/12329>\
**Category:** C++\
**Tags:** build, apple\
**Created:** [March 12, 2023, 1:46am UTC](https://forum.opencv.org/t/link-error-with-opencv-from-swift-on-m1-mac-building-for-ios-simulator/12329 "2023-03-12T01:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rayfix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rayfix/32/7370_2.png) [@rayfix](https://forum.opencv.org/u/rayfix)\
**Post date:** [March 12, 2023, 1:46am UTC](https://forum.opencv.org/t/link-error-with-opencv-from-swift-on-m1-mac-building-for-ios-simulator/12329/1 "2023-03-12T01:46:25Z")

</div>

I am using OpenCV through and Objective-C++ bridge vending a Swift API. I am linking the latest released iOS package of OpenCV 4.7.0.

It works great for devices (building using both Intel and Apple Silicon Mac), it works for simulators if I build on an Intel Mac.

However, if I build for the simulator on an Apple Silicon Mac (M1 Max), I get the following linker error:

ld: in /[redacted path]/opencv2.framework/opencv2(opencl\_kernels\_calib3d.o), building for iOS Simulator, but linking in object file built for iOS, file ‘/[redacted path]/opencv2.framework/opencv2’ for architecture arm64

Any ideas on how to resolve this? Any pointers greatly appreciated.

Thank you.

---

<div class="post-metadata">

**Author:** ![rayfix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/rayfix/32/7370_2.png) [@rayfix](https://forum.opencv.org/u/rayfix)\
**Post date:** [March 13, 2023, 9:59am UTC](https://forum.opencv.org/t/link-error-with-opencv-from-swift-on-m1-mac-building-for-ios-simulator/12329/2 "2023-03-13T09:59:25Z")

</div>

Someone pointed out in the Swift Forum that I need to build XCFramework to support the slices I want.

Looks like this is supported so what I am going to try soon.

> **[Build OpenCV Contrib as a .xcframework, for iOS, on a M1](https://weekly.elfitz.com/2022/06/14/build-opencv-contrib-for-ios/)**
>
> We needed an OpenCV Contrib module in an iOS app, using Swift Package Manager. I thought the hardest part would be using OpenCV. How wrong I was.
