views:

2969

answers:

4

Hi All,

Can I integrate my exsisting C++ library in an iPhone application?

Thanks & Regards

Khushi

+2  A: 

Objective C++ is well defined and supported by Apple's gcc.

But you can't mix C++ and objective C classes, which makes this rather messy pretty fast. I don't think there are many projects in the wild which mix C++ and Objective C to any serious extent.

This highly depends on your library, but if (realistically) feasible I'd wrap the C++ inside a C library, using extern "C" entrypoints for all real functionality, and link with that from inside your objective C code for your iphone app.

Pieter
A: 

Thanks for your support, but will it effect my application at the time of submision to Apple Store? Are there any chances of disapproval of application from Apple Store?

Thanks & Regards

Khushi

Khushi
Please edit your question rather than adding new queries as an "answer."
Stephen Darlington
+2  A: 

While it's true that you can't mix C++ classes in Objective-C, you can mix it with Objective-C++, which I believe is also supported in the iPhone. Integrating C++ code with an iPhone app shouldn't be an issue, but if you want to stay on the safe side, then you should build your code as a library and then link to it from your iPhone app; that way you don't need to worry about mixing Obj-C code and C++ classes.

As for Apple's approval, nobody can give you a definitive answer as to what may or may not qualify your app for inclusion in the store, since Apple is rather closed about the whole process. However, it's pretty clear by now that it's certain types of applications aren't going to make the cut; namely:

  • Apps that "abuse" or twist the iPhone SDK in ways Apple doesn't like. IE, setting the brightness of the device
  • Using too much bandwidth or system resources (draining battery life unnecessarily)
  • Duplicating Apple's functionality somewhere (ie, making a mail client, web browser, etc.)
  • Abusing the pricing tiers and schemes

Actually, it's better to just google for examples of banned apps to get a better feel for it. But the bottom line is, it's not how your app does something, it's what your app is doing which will lead to it being banned.

Nik Reiman
+1  A: 

I have just gotten started with iPhone development, but I have been able to successfully use some existing C++ libs without any changes. I brought over some OpenGL classes that I have already written and they work just fine since the gl libs on the iPhone are all C and not Obj-C. I am, for example, loading a texture into a GLubyte array using Obj-C to get the resources, size, etc. then passing those values to my C++ code which does the gl calls to create the texture. The same applies for loading geometry.

Just change your .m files to .mm and everything just seems to work. Objective C++ classes can have members that are C++ classes (though I don't think the other way applies, which could be a problem).

Dolphin