0
votes

I am using the OpenCV iOS Framework in a project. I followed the necessary steps to include the framework into the project.

The Project is written using Swift 3.

One of my classes that contains the core functionality of the App is written in Objective-C++. I included the header of the class in my Bridge-header file but when trying to run the project I get the following error:

error core.hpp header must be compiled as C++

After researching online and on SO, the most common solution presented was to create a Wrapper class that would be imported in the bridge header. However, after following this article I face the same problem.

The Header file of my class looks like this:

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#define IMAGE_CLASS UIImage
#elif TARGET_OS_MAC
#import <Cocoa/Cocoa.h>
#define IMAGE_CLASS NSImage
#endif

#import <AGGeometryKit/AGKQuad.h>

#import <stdio.h>
#import <opencv2/opencv.hpp>

#import <Foundation/Foundation.h>

typedef void (^DebugBlock)(cv::Mat current_image, std::string current_image_name);

@interface ImageScanner : NSObject

/**
 *  Singleton for access to the scanner.
 *
 *  @return Shared scanner.
 */
+ (instancetype)sharedScanner;

Does anyone have an idea what I might be missing?

Thank you in advance! G.

1
The bridging header file is compiled as (Objective-)C and not as C++. You can include the .hpp file only from the implementation (.mm) file of the wrapper class, not from the .h file (because then it would indirectly be included from the bridging header file). See Step 6 in the tutorial that you linked to. - Martin R
@MartinR Yes but how can I then declare properties and methods in my .h file that reference opencv if I include them only in the .mm file? - Granit
You can't. The is no bridging between Swift and C++. The wrapper must expose a pure C (or Objective-C) interface, and can use C++ classes only internally. - Martin R
Do you have any idea of how I should approach this issue since those methods are of importance to the functionality of the Scanner? - Granit

1 Answers

1
votes

had the same problem.. solved by importing any file that use openCV in the wrapperClass.mm file ...

SO Answer here