views:

31

answers:

2

Hello,

when I create an xCode project with the 'Command Line Tool' c++ stdc++ template, i am able to include and compile opencv headers and run some code.

But i want to use OpenCV in a 'Cocoa Application' context. When created with that template, i got compile errors when I include the OpenCV headers in main.mm. (I already changed main.m to main.mm, the '//NSApplicationMain(argc, (const char **) argv);' is commented out)

One of those errors is: "Statement-expressions are allowed only inside functions"

I suppose its some kind of compiler version error, but when i compare the project build settings i cant find differences.

Do you have any ideas/expertise?

A: 

Try adding: -lstdc++ to the "Other linker flags" in the build settings for your Cocoa app.

A cocoa application made by the Xcode templates won't link include the c++ library in it's settings by default.

petert
hi, i also added -lz, but still got the the same error. I am building on i386. What am i missing?
Why are you commenting out NSApplicationMain()? You'll have to update your question with more specific information, like the exact error message and / or enough of a code snippet for clues to the problem.
petert
A: 

You'll probably find it easier to use OpenCV's C API rather than the C++ API. You can call C APIs directly from Objective C of course, so this makes life a lot easier. You just lose some of C++'s syntactic sugar, like default parameter values.

Paul R