+ Reply
Results 1 to 5 of 5

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


Thread: Using old C++ code with Objectice C

is a discussion within the

iPhone / iPod Touch SDK | Development Discussion

forums, a part of the

3rd Party Apps For iPhone | iPod Touch

section;
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
...
  1. #1
    What's Jailbreak?
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    What's Jailbreak?
    Join Date
    May 2008
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 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.

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

    ajrulez (06-10-2008)

  4. #3
    iPhone? More like MyPhone
    Join Date
    Mar 2008
    Posts
    195
    Thanks
    14
    Thanked 21 Times in 17 Posts

    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
    What's Jailbreak?
    Join Date
    May 2008
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    Developer NetMage's Avatar
    Join Date
    Aug 2007
    Location
    Virginia
    Posts
    1,296
    Thanks
    72
    Thanked 210 Times in 168 Posts

    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