Mix Objective-C and C++ and OpenCV

情到浓时终转凉″ 提交于 2019-12-03 22:21:35

I had the same issue. I imported the Open-CV header before the UIKit headers. Make sure you do this in the pch file. The issue is with some macro defined in both UIKit and OpenCV.

Source: http://computer-vision-talks.com/2011/01/using-opencv-in-objective-c-code/

Maunil

I actually relied on the private framework (and sample project) provided by this guy: http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

I managed to use the same approach he did in the sample for use in my Objective-C mac app. Namely, the use of the import directive in the .PCH file as well as using .mm for Objective-C files that relied on any OpenCV C++ code/classes.

Another (unrelated?) thing worth mentioning, at least in xcode 4.5, is that you have to change your C++ standard library to 'libstdc++' in your target settings to get openCV to compile.

the OpenCV headers must be included before UIKit.h and Foundation.h because OpenCV defines a MIN macro that conflicts with the MIN function defined by the Apple frameworks. If you include the OpenCV headers after UIKit.h and Foundation.h you will receive compilation errors such as ‘LLVM GCC 4.2 Error: Statement-expressions are allowed only inside functions’. Including the OpenCV headers first and surrounding the #import with the __cplusplus conditional test avoids this problem and means that you can still use plain Objective-C for ‘.m‘ files in your project that don’t call the OpenCV APIs.

http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!