Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to port from Objective-C to C++?

I have no Objective-C experience whatsoever but have a strong C++ background. Is there an automated tool/script or, worst case, some manual method using some excellent reference to port code written in Objective-C to C++? What are the difficulties involved?

Edit: I'm told the code uses Objective-C fairly trivially. It's an iPhone app that probably doesn't use much in the way of OS-level UI. The C++ version is meant for a non-Apple platform where GNUStep is not an option, so Objective-C++ is not an option.

like image 802
Jim Buck Avatar asked Apr 01 '09 03:04

Jim Buck


2 Answers

I worked on same problem. And have some solutions:

  • Microsoft now offers its own Objective C "bridge", albeit only for UWP apps.

    https://github.com/Microsoft/WinObjC

  • In 2007 I tried to support Objective-C in Visual Studio and wrote my own ObjC runtime, but I do not have more time for writing parser for it. If you have, you can :)

    http://code.google.com/p/qobjc/

  • I wrote the basic functionality of Foundation Framework in C++. In this case, you need to port manually; your code will be on C++ but it will be like on Objective-C. This library worked on iPhone.

    http://code.google.com/p/dcocoa/

like image 163
DoctorSet Avatar answered Sep 19 '22 16:09

DoctorSet


There are no automated tools that I'm aware of. The dynamic nature of Objective-C is very hard to translate to C++, so quite a bit of brain effort is going to be required for all but trivial Objective-C code. Are you willing to stay on OS X (or keep the GNUStep dependency if you're one of the few people using Objective-C on an OS besides OS X)? If so, the easiest approach is to use Objective-C++ to build a bridge beteen the Objective-C and C++ code. Objective-C++ is an Apple extension to Objective-C and the GCC compiler that allows you to mix Objective-C and C++ code. You can thus create Objective-C objects that call or reference (but not inherit from) C++ objects and you can send Objective-C messages to Objective-C instances from within C++ code.

like image 37
Barry Wark Avatar answered Sep 20 '22 16:09

Barry Wark