Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We've developed a game engine written in C++. Now we are preparing our game engine for iOS developers.

I guess that many game developers use C++ or Objective-C for their game apps. So I think we should expose the API of our library in both Objective-C (@class blahblah) header files and in C++ (class blahblah) header files.

Am I on the right track? If not, what is the most recommended way of exposing the API for our library?

share|improve this question
up vote 3 down vote accepted

Since one can use C++ libraries in Objective-C also, there's actually no need to create special Objective-C header files.

Box2D for example is a pure C++ physics engine but is used in a lot of games, even ones written in Objective-C.

The only caveat (for developers using your library) is that

you still need to instruct the compiler to build all files that use C++ headers as Objective-C++ rather than Objective-C.

(as per Sam's comment)

share|improve this answer
This is not strictly true; you still need to instruct the compiler to build all files that use C++ headers as Objective-C++ rather than Objective-C. – sam hocevar Dec 12 '11 at 12:20
@SamHocevar That's right. But in any case there's no need to write special Objective-C header files. – bummzack Dec 12 '11 at 12:43
Yes, that wasn't intended as criticism. Or at least, I hoped to be constructive :-) – sam hocevar Dec 12 '11 at 12:45
May I ask out of curiosity if the C++ STL is also available? And is it also possible to take advantage of Boost? – David Gouveia Dec 12 '11 at 17:48
@davidluzgouveia As long as you're using portable code (that will compile for the ARM6/7 family), then basically all C++ code should work. C++ STL and Boost are very portable and should work fine. – bummzack Dec 12 '11 at 17:56

You can use Objective-C++ by naming your files with the extension .mm. This way, you can use both Objective-C classes(NSString, UIView) and c++ classes(classes in your c++ engine).

There is no need to rewrite your engine on Objective-C.

share|improve this answer

I had the same issue 2 years ago. What I end up doing is adding some additional functionality written in Obj-C where I host my engine. I limit my use of ObjC to creating UIView with OpenGL support, translating touch events to engine touch events, some file system calls to get the application data folder. All this exists only in my Engine project. In the apps themselves I write only in C++ using C++ interfaces.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.