简体   繁体   English

将opencv2.framework链接到Swift Xcode项目时出错

[英]Error when linking opencv2.framework to Swift Xcode project

I'm trying to import opencv2 framework to my Swift project. 我正在尝试将opencv2框架导入我的Swift项目。 The problem is that the project couldn't be built. 问题在于该项目无法构建。 Following are some of erros: 以下是一些错误:

"cv::medianBlur(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
"cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
"cv::contourArea(cv::_InputArray const&, bool)", referenced from:

In my Swift project, I have a .pch file named ProjectName-Prefix.h with content: 在我的Swift项目中,我有一个名为ProjectName-Prefix.h的.pch文件,其内容为:

#ifndef MyScanner_Prefix_pch
#define MyScanner_Prefix_pch

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif

#endif /* MyScanner_Prefix_pch */

How can I fix the errors? 如何解决错误? Actually, I saw some other projects on Github written in Swift which also integrate opencv2 and I tried to import all necessary frameworks, but I didn't succeed. 实际上,我在Github上看到了一些其他用Swift编写的项目,这些项目也集成了opencv2,我试图导入所有必要的框架,但没有成功。

I think you should try an alternative approach which is cocoapods . 我认为您应该尝试一种替代方法,即cocoapods While adding the opencv framework manually, I myself spent too much time to resolve these kind of issues but did not get succeed. 在手动添加opencv框架时,我本人花费了太多时间来解决这类问题,但没有成功。 so I recommend you to go for pods; 所以我建议你去吃豆荚;

pod 'OpenCV', '~> 2.4.10'

By comparing architectures between my project and the one downloaded from GitHub, I found out the solution. 通过比较我的项目和从GitHub下载的项目之间的架构,我找到了解决方案。 The project from GitHub is an outdated project (3 years ago) and it uses arm7 and arm7s while my project is created in Xcode 7 with an additional architecture (arm64). 来自GitHub的项目是一个过时的项目(3年前),它使用arm7和arm7s,而我的项目是在Xcode 7中创建的,具有附加架构(arm64)。 Arm64 is mandatory for new apps and the framework on cocoapods support arm64 (many thanks to @Shoaib). Arm64是新应用程序所必需的,可可足类框架也支持arm64(非常感谢@Shoaib)。 However, there is another issue with a library named "libjpeg.a" that we have to solve it manually. 但是,名为“ libjpeg.a”的库还有另一个问题,我们必须手动解决它。 People who have the same problem like me can check this link for the issue of "libjpeg.a" 像我一样有同样问题的人可以检查此链接是否存在“ libjpeg.a”的问题。

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

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