简体   繁体   English

Cocoapods OpenCV 2.4.10链接器错误

[英]Cocoapods OpenCV 2.4.10 Linker Error

I'm trying to build a simple project using OpenCV 2.4.10 but I get a bunch of errors like this: 我正在尝试使用OpenCV 2.4.10构建一个简单的项目,但是我得到了一堆这样的错误:

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 这是ViewController.m

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

@interface ViewController ()

@end

@implementation ViewController

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

Podfile 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. 当我使用2.4.9.1或2.4.9版时,Project构建得很好。
I was also able to build this project with framework file downloaded from URL which I found in podspec 2.4.10. 我还能够使用从podspec 2.4.10中找到的URL下载的框架文件构建此项目。

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. 错误4052仍未解决2.4.10并且没有2.4.11的pod,所以你必须使用2.4.9 IMO是稳定的。

If your using pods 如果你使用pods

pod 'OpenCV', '2.4.9'

So here's a little workaround. 所以这里有一点解决方法。 The problem is because the XCode project is unable to link to the libjpeg.a library. 问题是因为XCode项目无法链接到libjpeg.a库。 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. 转到:[[ http://sourceforge.net/projects/libjpeg-turbo/files/1.4.0/]]并下载libjpeg-turbo-1.4.0.dmg(3.8 MB)文件。
  2. Install the package. 安装包。 Once its done you will find the installed files under this path : /opt/libjpeg-turbo/lib 完成后,您将在此路径下找到已安装的文件: / opt / libjpeg-turbo / lib
  3. Open up your terminal and type the following command : lipo -info /opt/libjpeg-turbo/lib/libjpeg.a 打开终端并输入以下命令: 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) 如果终端在运行命令后显示以下输出,则意味着,您可以将该库用于您的iOS项目(armv7 / armv7s)
    • Architectures in the fat file: /opt/libjpeg-turbo/lib/libturbojpeg.a are: i386 x86_64 armv6 armv7 armv7s arm64* 胖文件中的体系结构:/opt/libjpeg-turbo/lib/libturbojpeg.a是: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. 使用finder导航到:/ opt / libjpeg-turbo / lib并复制libjpeg.a并将其放在项目文件夹中。
  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 转到你的XCode项目 - >点击Project Name - > Targets - > General - > Linked frameworks and libraries - >点击底部的添加按钮 - >包含libjpeg.a文件
  7. Compile the project. 编译项目。 It shouldn't show any more libjpeg linker errors. 它不应该再显示libjpeg链接器错误。

Seems to be an issue with the current version of Open CV for iOS 似乎是当前版本的Open CV for iOS的一个问题

Bug #4052 Bug#4052

Probably have to keep using 2.4.9. 可能必须继续使用2.4.9。

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. 并将此项目的框架和标题复制到我的项目中。 在此输入图像描述

I've added the new versions of OpenCV to CocoaPods (2.4.11, 2.4.12, 2.4.12.3, 3.0.0). 我已经将新版本的OpenCV添加到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. 2.4.11,2.4.12和2.4.12.3需要链接libjpeg,所以现在pod实际上下载了repo,从源代码编译,然后除了opencv2.framework文件之外还链接libjpeg。 This works out of the box now through CocoaPods, however it takes a while when doing pod install since it's compiling from source. 现在通过CocoaPods开箱即用,但是在进行pod install时需要一段时间,因为它是从源代码编译的。 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). 只是确保在它执行时不取消它(CocoaPods中的一个错误会导致问题,如果它被取消)。

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. 在引擎盖下,3.0.0与之前的opencv2.framework文件一样工作,现在可以通过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. 版本2.4.10在CocoaPods中仍然被破坏,但由于该版本在我的机器上从源代码编译时会抛出错误,所以我无能为力。

(Note: I am not the original maintainer of the pod, I merely contributed these new versions.) (注意:我不是pod的原始维护者,我只贡献了这些新版本。)

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 http://blog.csdn.net/iOSLearner_Nana/article/details/45174365

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM