17

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

Y2theZ
  • 10,162
  • 38
  • 131
  • 200
  • I have the same issue with an older version of the RestKit framework. There is a new version available by RestKit, only that requires a lot of changes in the code which uses the framework. When I find something I'll let you know. – Ben Groot Sep 19 '12 at 09:53
  • http://stackoverflow.com/questions/9539617/iphone-opencv-libraries-built-for-armv7 – Ken Sep 21 '12 at 07:15
  • @Ken yes I was using this one untill the new architecture came out. I need it for armv7s the link provied is for armv7 (without the s) – Y2theZ Sep 21 '12 at 07:25

7 Answers7

15

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.

Hammer
  • 10,109
  • 1
  • 36
  • 52
  • +1 for this. Thank you for going all the way to making the .framework file. I kinda became lazy at that step. This should be the answer. Wish we could split the bounty though! – Nandeep Mali Sep 26 '12 at 08:14
  • @n9986 I know. his answer is better since he went all the way. sorry I can't split the bounty beleive me I tried. (http://meta.stackexchange.com/questions/2786/accept-multiple-answers-or-split-bounty-among-several-users). Thanks anyway. – Y2theZ Sep 26 '12 at 12:47
  • @n9986 yeah that would be a great feature, I couldn't have done it without your answer, I had already spent a long time without getting anywhere. Thanks – Hammer Sep 26 '12 at 14:52
  • Do you know what would be necessary to also bundle in opencv built for i386 so it will compile in the simulator? – Liron Sep 28 '12 at 06:23
  • @LKIM see update. Let me know if you need more detailed instructions – Hammer Sep 28 '12 at 14:53
  • @Hammer I actually got it to work using one of the suggestions below, but if I have some time next week I'll try your suggestion too to make sure it works for me also. – Liron Sep 30 '12 at 08:28
  • @Hammer Thank you, I have it working with the simulator but not on the device, I get some "Apple Mach-O Linker errors" (53 of them). Any idea what could be the problem? Here is the complete log: http://pastebin.com/Br5qhgHJ – e-Jah Oct 05 '12 at 03:35
  • @e-Jah that is strange. If you go into the framework in terminal and type file opencv2 does it list armv7 and cputype12/cpusubtype11? – Hammer Oct 05 '12 at 17:28
  • @Hammer, yes: `opencv2: Mach-O universal binary with 2 architectures opencv2 (for architecture armv7): current ar archive random library opencv2 (for architecture cputype (12) cpusubtype (11)): current ar archive random library ` – e-Jah Oct 06 '12 at 06:01
  • @e-Jah I'm sorry but I don't know why that shouldn't work then. Let me know if you figure it out – Hammer Oct 08 '12 at 15:00
  • Opencv [2.4.3](http://code.opencv.org/projects/opencv/wiki/ChangeLog#243) now supports armv7s by default so these solutions are outdated – Hammer Nov 05 '12 at 16:05
7

Clone the Xcode project for opencv and update the opencv git submodule as per the README:

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

Check the build settings, make sure iOS6 and armv7s are present. Click build. You should now have the armv7s compatible .a files. I just tried this:

$ file libopencv_core.a 
libopencv_core.a: Mach-O universal binary with 2 architectures
libopencv_core.a (for architecture armv7):  current ar archive random library
libopencv_core.a (for architecture cputype (12) cpusubtype (11)):   current ar archive random library

The last entry is for armv7s as per my research so far.

Edit: The last entry is indeed armv7s. I ran the Xcode's own lipo info command:

$ xcrun -sdk iphoneos lipo -info libopencv_core.a 
Architectures in the fat file: libopencv_core.a are: armv7 armv7s 
Nandeep Mali
  • 4,456
  • 1
  • 25
  • 34
  • It states so however it does not work with the armv7s architecture. same error as above. – Y2theZ Sep 24 '12 at 09:01
  • You can also try this with the libraries: http://www.galloway.me.uk/2012/09/hacking-up-an-armv7s-library/ See if this works. This is a way to hack it up for a successful build but everyone is reporting a success in that method. – Nandeep Mali Sep 24 '12 at 09:22
  • @n9986 great suggestion, I found that as well but I haven't been able to get it to work yet. His script works, and a new valid architecture gets added to the library but there are still errors. If you manage to get it to work please post details – Hammer Sep 24 '12 at 17:28
  • @Hammer Will do. Trying to make it work was what I was up to in the day. Had some weird errors as well. I have asked a few doubts to the author directly. Let us see if it turns up something. I'll try again at work tomorrow. If something comes up, will drop it here. – Nandeep Mali Sep 24 '12 at 17:43
  • Just updated the answer after trying out the XCode project uploaded by someone. Some libs don't build due to dependencies (until you install them of course), but the core seems to work just fine. – Nandeep Mali Sep 25 '12 at 13:08
  • how to compile same library for all I mean for architectures:armv7,armv6,i386. It's working fine for device – Iducool Mar 04 '13 at 14:35
1

You can always just not target armv7s, and only target armv7. Your application will still run fine on the iPhone 5, it just won't be fully optimized for the new instruction set.

Cody C
  • 3,087
  • 4
  • 24
  • 32
  • I do not have control over the build. it is an automatic build script that gets run on a server. I can only send my code and it get built. And the script is using the armv7s framework – Y2theZ Sep 21 '12 at 07:28
  • Then somebody recently altered the configuration of the server and broke things. It's their responsibility to fix this. – Jim Sep 22 '12 at 11:06
1

Simply, I cloned source from here and build with this tutorial.

Then I got opencv2.framewok that works with armv7, armv7s and simulator.

mmtootmm
  • 800
  • 6
  • 17
0

Stating the obvious, you will need to recompile and rebuild the library openCV.framework and target it for armv7s.

Adjust the library "project settings" and "target settings" before rebuild. good luck!

dklt
  • 1,703
  • 1
  • 12
  • 12
0

Probably its possible to build it with CMake. I had one year ago a problem with a medical library I wanted to build for iOS. I could handle that with CMake.

Perhaps this link can be a starter.

http://computer-vision-talks.com/2010/12/building-opencv-for-ios/

Good luck!

NDY
  • 3,527
  • 4
  • 48
  • 63
0

Pass -DCMAKE_OSX_ARCHITECTURES="armv6;armv7;armv7s;i386" to cmake when compiling OpenCV library/framework for iOS.

Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • 1
    This actually worked for me, in the end. Had to add that line into the build_framework.py script and I got a build OpenCV2.framework with armv7, armv7s and i386 libs in it. (I don't need armv6 so I removed that.) – Liron Sep 30 '12 at 08:28