Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.
06-09-2008, 09:59 PM #1Using old C++ code with Objectice C
What is the best way to integrate old C++ code with Objective C for iPhone applications?
I am just starting to experiment with the iPhone SDK. I have a large number of C++ classes that I want to port over to the iPhone and I am wondering what is the best way to achieve this?
06-09-2008, 11:32 PM #2
Just import .h files from inside your objective code, then call your C++ functions normally. In your makefile change the compiler from arm-apple-darwin-gcc to arm-apple-darwin-g++. However, iPhone only supports standard C/C++, so sometimes it can't compile your C++ code if it contains advanced functions.
The Following User Says Thank You to vieestchien For This Useful Post:
06-10-2008, 10:13 PM #3
06-12-2008, 01:08 AM #4
Yes ANSI C++ would work.
If you write c++ code directly in your Objective-C files, you need to change the extension from .m to .mm.
06-12-2008, 05:32 PM #5
I use a custom makefile that compiles .mm in Objective-C++ and .m as regular Objective-C (well with gnu extensions and C-99).
Works very well, and allows some nice C++ stuff to be used (variable declarations, etc.)Starlight Computer Wizardry
Follow me on twitter: @NetMage