2

Possible Duplicate:
Is it possible to program iPhone in C++

I have an existing C++ code that i want to re-use in iPhone/iPade application (and don't want to have to rewrite it all in Objective C),How can I include this code into my iPhone application?

I tried with Xcode 4.5, but I had several compilation error.

Community
  • 1
  • 1
Aladin Lazhar
  • 33
  • 1
  • 5

3 Answers3

3

That should be as simple as this: use the extension .mmfor all your ObjC files from where you call your C++ code. This will actually make you files handled as Objective-C++ file (which is just the same as Objective-C with the added capability of calling into C++ code).

If you still have errors after doing that, then post the error messages.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I switch to.mm ,i get this error "'iostream' file not found",when i ran the application – Aladin Lazhar Jan 10 '13 at 12:56
  • the question has been closed, but anyway, if you are including iostream from a `.mm` file, then check in your target build settings for that file that the Objective-C++ compiler is also being used. If you just changed the extension to a .m file it might be still treated as a ObjC file. – sergio Jan 10 '13 at 18:31
1

create .cpp files.

when you create a new file, you can choose to create c++ files.

Also, sergio suggests it right

Nikita P
  • 4,226
  • 5
  • 31
  • 55
0

I wrote a C++ wrapping for a objective-c class recently. The important thing about separating oc and C++ is that you shouldn't include C++ .h files in oc .h files, and to do this you can use void* pointers.

see: Calling Objective-C method from C++ method?

Community
  • 1
  • 1
JasonLi
  • 182
  • 2
  • 8