Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 and openCV (no Swift): Core.hpp header must be compiled as C++

I have followed the instructions on how to install OpenCV on an iOS project. However when using Xcode 7 I had to add manually a prefix header. Doing this unfortunately did not help and I was still getting compile errors. I then read another post suggesting that is best to add manually the imports and not use prefix headers in Xcode 7, so I did.

Here is my code:

#import "ViewController.h"

#import <opencv2/opencv.hpp>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <opencv2/highgui/cap_ios.h>
//using namespace cv;

@interface ViewController ()
{
    IBOutlet UIImageView* imageView;
    IBOutlet UIButton* button;
}

- (IBAction)actionStart:(id)sender;

@end

However I still get the following errors.

enter image description here enter image description here

When I uncomment the using namespace cv; I get the following:

enter image description here

I found some complex solutions talking about exposing headers to Swift etc.. I just want my project to work on Objective-C with Xcode 7 ...

like image 723
mm24 Avatar asked Mar 07 '16 09:03

mm24


1 Answers

OpenCV is a C++ framework, which means that any code that makes use of OpenCV has to be compiled with C++ interpretation, rather than C interpretation.

The errors you see, e.g. with the using namespace cv; indicate that the code is compiled using the objective-C compiler, rather than the objective-C++ compiler.

As I mentioned in my comment the easiest way to get this to happen is to ensure that any file that #includes an opencv header must be named e.g. ViewController.mm, i.e. it must be an Objective-C++ file.

Alternatively, you can select and override the Type of the file, by explicitly selecting the Objective-C++ Source option for the file type in the utilities pane. utilities pane drop-down selection

like image 93
Petesh Avatar answered Oct 11 '22 06:10

Petesh