Xcode 7和openCV(没有Swift):Core.hpp头必须编译为C ++ [英] Xcode 7 and openCV (no Swift): Core.hpp header must be compiled as C++

查看:231
本文介绍了Xcode 7和openCV(没有Swift):Core.hpp头必须编译为C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经关注了



当我取消注释using namespace cv时;我得到以下内容:





我发现了一些复杂的谈论暴露标题到Swift等的解决方案..我只是希望我的项目能够使用Xcode 7在Objective-C上工作...

解决方案

OpenCV是一个 C ++ 框架,这意味着任何使用OpenCV的代码都必须使用 C ++编译解释,而不是 C 解释。



您看到的错误,例如使用命名空间cv; 表示代码是使用objective-C编译器编译的,而不是使用objective-C ++编译器。



正如我在评论中提到的,实现这一目标的最简单方法是确保任何 #include 的文件都必须命名为opencv标头,例如 ViewController.mm ,即它必须是Objective-C ++文件。



或者,您可以选择并覆盖通过在实用程序窗格中为文件类型显式选择 Objective-C ++ Source 选项,键入该文件的


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.

这篇关于Xcode 7和openCV(没有Swift):Core.hpp头必须编译为C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆