opencv可以与Objective C一起编译用于OS X应用程序开发吗? [英] Could opencv mix compile with Objective C for OS X app development?

查看:77
本文介绍了opencv可以与Objective C一起编译用于OS X应用程序开发吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OSX的默认GUI(例如NSImageView)来显示OS X应用程序(不是iOS)的OpenCV图像,因此我需要将Objective C与C ++一起使用,这对于Apple LLVM编译器来说没什么大不了的.但是当涉及到OpenCV时,即使只是将opencv2/opencv.hpp导入到".mm"文件中,也会使构建崩溃.

I want to use OS X default GUI like NSImageView to show an OpenCV image for an OS X app(not iOS), so I need to use Objective C with C++, it's not a big deal for Apple LLVM compiler. But when it comes to OpenCV, even just to import opencv2/opencv.hpp in to a '.mm' file will crash the build.

我收到错误消息:期望的会员名或';' OpenCV Utility.hpp中的'bool check()const;'.

I got the error:"Expected member name or ';' after declaration specifiers" in OpenCV utility.hpp line 'bool check() const;'.

我搜索了此内容,我在这里有一个类似的问题(混合目标- C,C ++和OpenCV ).这个问题与可可和OpenCV中定义的某些宏有关.答案是在".pch"文件中的Cocoa标头之前导入OpenCV标头.

I searched for this, I have a similar question here (Mix Objective-C and C++ and OpenCV). This problem is with some macro defined in both Cocoa and OpenCV. The answer is to import OpenCV header before Cocoa headers in '.pch' file.

默认情况下,iOS模板具有".pch"文件,而OS X模板则没有.因此,我添加了一个没有运气的".pch",它也不会编译.

By default an iOS template has a '.pch' file but OS X template don't. So I add a '.pch' with no luck, it won't compile either.

所以我的问题是我该如何做类似iOS解决方案的事情?如何使用OpenCV编译OS X?

So my question is how can I do the same thing like the iOS solution? How can I get my OS X compile with OpenCV?

推荐答案

您可以在需要时直接在源文件中直接导入/包含opencv标头,但是请确保在包含Cocoa标头之前做到这一点.

You can just import / include opencv headers directly in your source file when you need it, but make sure to do so before including Cocoa headers.

例如,我需要在ViewController.h中使用OpenCV,所以我在ViewController.h中执行了以下操作:

For example, I need to use OpenCV in ViewController.h so I did the following in ViewController.h:

#ifdef __cplusplus
#import <opencv2/core/core.hpp>
#endif

#import <Cocoa/Cocoa.h>

现在,这是棘手的部分:您还需要注意依赖ViewController.h的文件.具体来说,任何其他导入ViewController.h的Cocoa文件都需要首先导入该文件(甚至在其自己的标头之前,因为其自己的标头已经已经导入了一些Cocoa标头).

Now, here is the tricky part: you also need to be careful for files that depend on ViewController.h. Specifically, any other Cocoa files that import ViewController.h will need to import this file first thing (even before its own header, because its own header will import some Cocoa headers already).

这篇关于opencv可以与Objective C一起编译用于OS X应用程序开发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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