Results 1 to 5 of 5

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Using old C++ code with Objectice C

  1. #1
    Default Using 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?

    Thank you...

  2. #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.

  3. The Following User Says Thank You to vieestchien For This Useful Post:

    ajrulez (06-10-2008)

  4. #3
    Quote Originally Posted by vieestchien View Post
    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.
    Wow..thats good to know So ANSI C++ code will work on iPhone just fine?

  5. #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.

  6. #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
    Pocket-sized Development
    Follow me on twitter: @NetMage

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •