lenhhoxung
lenhhoxung

Reputation: 2746

Error when linking opencv2.framework to Swift Xcode project

I'm trying to import opencv2 framework to my Swift project. 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:

#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.

Upvotes: 0

Views: 736

Answers (2)

lenhhoxung
lenhhoxung

Reputation: 2746

By comparing architectures between my project and the one downloaded from GitHub, I found out the solution. 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). Arm64 is mandatory for new apps and the framework on cocoapods support arm64 (many thanks to @Shoaib). However, there is another issue with a library named "libjpeg.a" that we have to solve it manually. People who have the same problem like me can check this link for the issue of "libjpeg.a"

Upvotes: 0

Shoaib
Shoaib

Reputation: 2294

I think you should try an alternative approach which is cocoapods. While adding the opencv framework manually, I myself spent too much time to resolve these kind of issues but did not get succeed. so I recommend you to go for pods;

pod 'OpenCV', '~> 2.4.10'

Upvotes: 1

Related Questions