Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate C++ library into iPhone app

Tags:

c++

xcode

ios

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

like image 437
Khushi Avatar asked Nov 21 '08 12:11

Khushi


People also ask

Can you make iPhone apps in C?

Is it possible to build an iPhone app purely in the C programming language? Possible? Yes.

Can you still make iOS apps with Objective-C?

If you use Objective-C to develop an iOS or OS X application, you will most probably use the Xcode IDE. There are other environments available like AppCode or Visual Studio Code from Microsoft, but they need Xcode underneath to work properly.

What is an Objective-C framework?

It is a bundle (Directory structure) that contains shared libraries as well as sub directories of headers and other resources. However Frameworks can include the following, Shared Library. Header Files describing the API.


3 Answers

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.

like image 82
Nik Reiman Avatar answered Oct 05 '22 17:10

Nik Reiman


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.

like image 44
Pieter Avatar answered Oct 05 '22 17:10

Pieter


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).

like image 31
Dolphin Avatar answered Oct 05 '22 17:10

Dolphin