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

opencv swift
opencv 4.x+ requires enabled c++11 support

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.

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

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

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.

OpenCV Error - Core.hpp header must be compiled as C++, Put anything OpenCV, or standard C++, in MMOpenCVHelper.mm . in SomeSwiftFile.swift you can do (please verify this since I'm not very familiar with Swift): OpenCV => 3.1.0.1 Operating System / Platform => MacOS sierra Compiler => Xcode Detailed description I use cocoapod to install opencv in my project. I had no problem with opencv 2+, only with the 3+ version.

I just had the exact same problem. I'm working in a Swift project with OpenCV.

Regarding Swift, its entry point to OpenCV is a file I called OpenCVWrapper. So I got OpenCVWrapper.h and OpenCVWrapper.mm. In the bridging header of my project, I got #import "OpenCVWrapper.h".

Thing is I wanted to write a class called MatUtils in Objective-C++ that I could call from OpenCVWrapper.mm. For them to be seeable in there, I had to put them in MatUtils.h.

Long story short, the mistake is that in OpenCVWrapper.h, I did #import "MatUtils.h". MISTAKE!!!! As OpenCVWrapper is in the bridging header, C++ is now reachable from Swift!

Quick fix : #import "MatUtils.h" in OpenCVWrapper.mm!

Cheers! bRo

🤟 Xcode 7 and openCV (no Swift): Core.hpp header should be , Xcode 7 and openCV (no Swift): Core.hpp header must be compiled as C++ - c​++ to Swift etc.. I just want my project to work on Objective-C with Xcode 7 . @alalek Assumption about relative path in #include "path" form is not a part of C++ standard actually. It is compiler-specific. This has nothing to do with a compiler, #include is resolved by the preprocessor.

Try placing #import < opencv2/opencv.hpp > before #import "ViewController.h".Source

Implicit declaration if function in C99, Xcode 7 and openCV (no Swift): Core.hpp header must be compiled as C. Question. I have followed the instructions on how to install OpenCV on an iOS project. I can't build project with a new version of the opencv 3.0.0 framework (version 2 DID NOT have this problem). Xcode 7 does not compile c++ sources as c++. Here's the simplest setup that is not building:

Xcode 7 does not build ios swift project with c |Apple Developer , OpenCV is a C++ framework, which means that any code that uses OpenCV must be compiled with a C++ interpretation, not a C interpretation. Errors that you  Hi, Recently github enabled opencv's extra classes through Python-for-android (including the face class). It has no trouble detecting the face binding boxes.

Core hpp header must be compiled with C++, I had no problem with opencv 2+, only with the 3+ version. Learn & contribute This is in the types_c.h (this file is in the opencv framework): __cplusplus # error core.hpp header must be compiled as C++ #endif #include  openalpr-ios. A Ruby script that builds an Xcode project and a universal iOS static library framework for the openalpr library. As of this writing, this project is compatible with the 2.2.x release of OpenALPR and later.

opencv Knowledge Base, After compiling in Xcode I get the following errors: "Core.hpp header must be compiled as C++" header must be compiled as C++" "Base.hpp header must be compiled as C++" "climits file not found". I have setup OpenCV 2.4.9 the following way (Cmake installed): git Cut the photo without losing faces. I got it working. Apparently I have made a mistake by installing OpenCV at /usr. When I set Header Search Path to /usr/include XCode picks some unnecessary headers and fails to link my project it seems. I followed your tutorial from the beginning and the it worked. 🙂 Thanks for the help. One addition, third include in your code is redundant

Comments
  • The code requires C++ features; you have to use objective C++, not objective C. The quickest 'workaround' is to rename your .m file to .mm; but this is kicking the fact that you're now writing C++ down the road at that point.
  • I tried but it still won't work..
  • Did you get this to work? @mm24
  • thank you for the clear explanation. I will try this tomorrow and let you know how I got on.. cheers, and thanks a lot for replying :)
  • @mm24 did you ever get around this problem? I'm facing same issue and none of the solutions seem to work. :/
  • I had to stop working on this and find an alternative solution. I tried but not enough to confirm whether it works or not. I accept as it has 4 up-votes and sounds sensible.
  • Just ran into a similar issue. After a few minutes I realized that I could re-open the interface in the .mm and place the instance properties inside that, rather than the main wrapper.h which otherwise had put me into a recursion :-)
  • Yes! I think you were following this medium.com/compileswift/ios-opencv-and-swift-1ee3e3a5735b which wasn't real clear about that, thanks.
  • Hello, indeed I was following that article, because I'm the one that wrote it haha. I have to update that article, some things are out of date :)
  • @bRo, did you end up updating? I am having the same problem but I followed the same steps as your article and the other ones.
  • Not yet, I'll find time soon, I promise :)