25

I'm trying to build a simple project using OpenCV 2.4.10 but I get a bunch of errors like this:

Undefined symbols for architecture x86_64:
  "_jpeg_free_large", referenced from:
      _free_pool in opencv2(jmemmgr.o)
  "_jpeg_free_small", referenced from:
      _free_pool in opencv2(jmemmgr.o)
      _self_destruct in opencv2(jmemmgr.o)

Here is ViewController.m

#import "ViewController.h"
#import <opencv2/opencv.hpp>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    cv::Mat greyMat;
}

Podfile

platform :ios, '8.1'

pod 'OpenCV', '2.4.10'

Project builds just fine when I use version 2.4.9.1 or 2.4.9.
I was also able to build this project with framework file downloaded from URL which I found in podspec 2.4.10.

1
  • 1
    Person who downvoted - please also tell WHY you downvoted it. Problem exists. Commented Feb 9, 2015 at 7:44

6 Answers 6

18

Bug 4052 is still unsolved for 2.4.10 and there is no pod for 2.4.11 so you have to use 2.4.9 which IMO is stable.

If your using pods

pod 'OpenCV', '2.4.9'
Sign up to request clarification or add additional context in comments.

1 Comment

The pod distribution seems to be broken (SourceForge link errors). See stackoverflow.com/a/31226206/1375695 for a fix.
11

So here's a little workaround. The problem is because the XCode project is unable to link to the libjpeg.a library. So thats why you get the above errors when you compile the project.

Follow these steps :

  1. Go to : [[http://sourceforge.net/projects/libjpeg-turbo/files/1.4.0/]] and download the libjpeg-turbo-1.4.0.dmg (3.8 MB) file.
  2. Install the package. Once its done you will find the installed files under this path : /opt/libjpeg-turbo/lib
  3. Open up your terminal and type the following command : lipo -info /opt/libjpeg-turbo/lib/libjpeg.a
  4. If the terminal shows the following the output after running the command then it means, you can use the library for your iOS project(armv7/armv7s)
    • Architectures in the fat file: /opt/libjpeg-turbo/lib/libturbojpeg.a are: i386 x86_64 armv6 armv7 armv7s arm64*
  5. Use finder to navigate to : /opt/libjpeg-turbo/lib and copy libjpeg.a and place it in your project folder.
  6. Head over to your XCode project -> Click on Project Name -> Targets -> General -> Linked frameworks and libraries -> Click on the add button placed at the bottom -> include the libjpeg.a file
  7. Compile the project. It shouldn't show any more libjpeg linker errors.

3 Comments

This manual is cool! Thanks! I've simply add libjpeg.a from /opt/libjpeg-turbo/lib to my project. But I had to disable bitcode option in project settings. Because, as I understood, that lib has been compiled without bitcode option.
I recently set up to explore OpenCV on iOS and found that the recommended instruction to add the libjpeg.a to my project didn't cure the problem. Instead of having undefined symbols I got many duplicate symbols. I came up with a hack to fix that, which was to download the OpenCV sources and grabbing the following 8 files and adding them to my iOS project. This had the effect of defining the symbols exported by jmemansi.c. I don't know enough about XCode or the build system used in OpenCV to make a more elegant fix, but I thought i would pass along the solution that worked for me.
List of files I copied into my project: jconfig.h jinclude.h memsys.h jpegint.h jerror.h memansi.c jmorecfg.h jpeglib.h
5

Seems to be an issue with the current version of Open CV for iOS

Bug #4052

Probably have to keep using 2.4.9.

1 Comment

Can't use 2.4.9 as apps are now required to be 64bit.
2

I've added the new versions of OpenCV to CocoaPods (2.4.11, 2.4.12, 2.4.12.3, 3.0.0).

2.4.11, 2.4.12, and 2.4.12.3 need libjpeg to be linked, so now the pod actually downloads the repo, compiles from source, and then links libjpeg in addition to the opencv2.framework file. This works out of the box now through CocoaPods, however it takes a while when doing pod install since it's compiling from source. Just make sure not to cancel it while it's doing that (there's a bug in CocoaPods that causes issues if it's canceled).

Under the hood, 3.0.0 works just like before with the prebuilt opencv2.framework file and can now be installed just fine through CocoaPods.

Version 2.4.10 is still broken in CocoaPods, but since that version throws errors while compiling from source on my machine, there's not much I can do.

(Note: I am not the original maintainer of the pod, I merely contributed these new versions.)

3 Comments

Alas, using even a very simple Podfile, none of these work: pastebin.com/hbjNTF9H
shmim, that is very strange. What happens when you go to download.sourceforge.net/project/opencvlibrary/opencv-ios/3.0.0/… ? Are you able to download the file?
The sourceforge links weren't working when I posted my comment, but they appear to be working now. I've heard of this happening before... 3.0 downloads, and I'm presuming it works, although I haven't tested it yet. However, versions 2.4.11, 2.4.12, 2.4.12.3 all throw compiler errors: paste.ee/p/ACvj0
2

I don't have a solution for this one but I have a workaround here.I have downloaded the project from here . And copied the framework and header from this project to my project. enter image description here

Comments

1

The same issue I faced with open CV and found a useful link below that resolved my errors of my project :

http://blog.csdn.net/iOSLearner_Nana/article/details/45174365

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.