1

If so how should the C++ code be prepared so it's easily consumed in Obj-C code?

Also is this a valid way of creating cross platform applications if you choose not to use GTK or Qt?

Roman
  • 10,309
  • 17
  • 66
  • 101

3 Answers3

3

Yes, it's definitely possible. It's not even all that uncommon. For example, most of WebKit is C++ code. You can use Objective-C++ to bridge between C++ and Objective-C code.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • can the C++ code be made into a library in the way that dlls work on Windows and have the library imported into an xcode project? – Roman Dec 21 '11 at 02:12
3

Yes, we have shipping applications built this way. We have an OS layer (Obj-C on Mac, a Combination of C++, C++/CLI and C# combination on Windows) and a shared portable layer.

One primary concern is to be disciplined in the class definitions so that OS particulars (Obj-C or C++/CLI syntax for example) does not get used in the portable/shared code.

You could create libraries to isolate code but we haven't needed to do that.

jschroedl
  • 4,916
  • 3
  • 31
  • 46
  • I know in Windows you can use C++ code through DLLs but how do you import the C++ layer into your objective-c code? – Roman Dec 21 '11 at 02:19
  • We have an XCode project which simply includes both sets of files. We organize by folders but it's all included in the output application. We have static libraries for a few sets of C++ files which are simply linked into the main project as well. – jschroedl Dec 21 '11 at 04:27
2

Yes, it's possible and really useful. Sometimes it would better to split you application into 2 parts: Objective-C GUI application and C/C++ daemon with business logic. It simplifies cross-platform application development process.

  • 1
    Can the two be started and stopped together or the daemon must continuously run in the background? – Roman Dec 21 '11 at 02:16
  • You could use launchctl for managing your daemon activities, like start-up, restarting, termination, etc. http://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/launchctl.1.html http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html – Alexander Stavonin Dec 21 '11 at 03:46