Ask Your Question
1

Errors when trying to import the OpenCV framework into an iOS project

asked 2012-09-10 13:25:23 -0500

zenberg gravatar image

I downloaded the official version of iOS framework from opencv.org and then created a simple view-based Xcode project and added the opencv2.framework in the build phases menu.

After that I imported the opencv2.framework as:

#ifdef __cplusplus
#import <OpenCV/opencv2/opencv.hpp>
#endif

into the *.pch file.


I have this function:

static void testOpenCV
{
    cv::Mat m, gray;
}


When I ran the build - it showed me this error:

~/projects/xcode/openCV_ex/openCV_ex/ViewController.m:45:8: Expected expression


When I try to include the OpenCV framework before any definitions in my .pch file like this:

#import <opencv2/opencv.hpp>
#import <Availability.h>
….


I get this error:

~/Downloads/opencv2.framework/Versions/A/Headers/video/background_segm.hpp:48:1: Unknown type name 'namespace'



Can you please help me to find a solution to this problem?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2012-09-11 08:35:12 -0500

AlexanderShishkov gravatar image

Do you change type of your project to Objective-C++ in project options: Apple LLVM compiler 3.1 -> Compile Sources As?

edit flag offensive delete link more

Comments

I chose the option "Objective C++" in my Apple LLVM compiler 4.0 -> "Compile Sources As" and now it works! Thank you very much!

I am not sure if it is correct to post this question here, but in AppCode it still gives me an error that says that it can't resolve "cv::Mat". Can you please help with this one as well?

zenberg gravatar imagezenberg ( 2012-09-11 10:57:40 -0500 )edit

Could you add more detailed description of the problem, maybe with code sample and log of the error? It is better, if you do it as new question.

AlexanderShishkov gravatar imageAlexanderShishkov ( 2012-09-11 13:16:20 -0500 )edit

There is no error in the compiling time. It actually looks like an AppCode Editor issue and I decided to post the question on their official forum: http://devnet.jetbrains.net/thread/438446

zenberg gravatar imagezenberg ( 2012-09-12 20:50:42 -0500 )edit
2

answered 2012-09-14 00:54:59 -0500

hkaraoguz gravatar image

Hi,

Your ViewController.m file should be renamed as ViewController.mm in order to use OpenCV or any other C++ code inside that file.

edit flag offensive delete link more

Comments

It worked. Thank you very much!

zenberg gravatar imagezenberg ( 2012-09-14 13:16:44 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-09-10 13:25:23 -0500

Seen: 4,571 times

Last updated: Sep 14 '12