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

This is a little random, but I am stuck and wondering if someone here knows the answer and give me a push in the right direction.

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 actual devices (building using Intel and Apple Silicon Mac), it works for simulators if I build on an Intel Mac. Only 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

After a little wandering around, I am still feeling rather clueless about this error. I am wondering if I will need to build OpenCV from source and include more architectures somehow manually. Any pointers greatly appreciated.

Thank you.

Most lilkely that release zip has a fat binary framework for Intel (simulator) + ARM (devices) but it's missing the slice for ARM(simulator), but that slice cannot be inserted there anyway; This is the reason library vendors must move to the .xcframework format nowadays;
You probably have to rebuild the package from source in a .xcframework format.

1 Like

I am still feeling rather clueless about this error.

I suspect that costinAndronache is likely on the right track here. For general background to this issue, see An Apple Library Primer on DevForums.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Thank you for the info. Looks like someone has done this and blogged about it.