OpenCV.Framework does not compile for the armv7s architecture

Youssef picture Youssef · Sep 19, 2012 · Viewed 9.4k times · Source

I am working on an iphone application using openCV framework. Everything was working fine. however lately with the release of iOS 6 and XCode 4.5 I was migrating my project to XCode 4.5 When building I encountered this error:

ld: file is universal (2 slices) but does not contain a(n) armv7s slice: /Users/jobs/iPhone_Client/workspace/MyProject/third-party/OpenCV.framework/OpenCV for architecture armv7s clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

The following build commands failed: Ld build/MyProject.build/Debug-iphoneos/MyProject.build/Objects-normal/armv7s/MyProject normal armv7s (1 failure)

As I understood this is due to the new armv7s architecture. OpenCV is apparently it is not compiling with armv7s.

How can I fix this issue?

Where can I find a new release of the framework that is compatible with the armv7s architecture?

And if there is no compatible framework available, is there a way to get the source code and create my own library compiled against the new architecture? Maybe some quick steps on how to do it?

Note: Just to note that I need the build for armv7s not armv7. Thank you

Answer

Hammer picture Hammer · Sep 26, 2012

This answer builds upon the one given by n9986. As he suggested, I cloned the repository found at

https://github.com/jonmarimba/OpenCV-iOS

When I downloaded it several references inside the project to different libraries were broken which was strange but they were easy to fix. After they were fixed it behaved exactly as n9986 described, outputting libraries compiled for both armv7 and armv7s. For my purposes however I required that they be bundled into a .framework so that they could be a drop in replacement for the old .framework I have been using.

Previously I had downloaded the latest version of Opencv for ios here and spent quite a bit of time trying to modify their cmake files to compile with support for armv7s. jonmarimba has already restructured the xcode project file to strip away its cmake dependencies which makes changing the target architecture much more intuitive. Unfortunately he does not build as many libraries as come with the standard openCV build. I added a new target to jonmarimba's project for opencv_world which is the target used in the standard openCV release for converting into a framework. Once that was built I used it as a drop in replacement for the static library in the framework file structure generated by the standard openCV release.

The framework I created can be downloaded here. It works perfectly for me as a drop in replacement for my previous opencv2.framework. I did notice however that jonmarimba has not converted the targets for opencv_videostab, opencv_stitching, or opencv_nonfree. It is possible that if you use one of those libraries my framework will not work for you. If that is the case let me know and I can try to set those up as targets in the xcode project for you.

Update

To compile for other architectures, change the target architecture in the included xcode project to whatever you like for the opencv_world library. After you build it, go find the library you just built. Rename the opencv_world library to opencv2 and replace the library file found in the .framework with opencv_world.

Update2

OpenCV 2.4.3 now compiles with armv7s support by default so these solutions are outdated.