简体   繁体   English

从 Objective-C 移植到 C++ 的最佳方法是什么?

[英]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.我没有任何 Objective-C 经验,但有强大的 C++ 背景。 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++?是否有自动化工具/脚本,或者,最坏的情况,一些手动方法,使用对 Objective-C 到 C++ 中编写的端口代码的一些极好的参考? What are the difficulties involved?有哪些困难?

Edit: I'm told the code uses Objective-C fairly trivially.编辑:有人告诉我代码使用 Objective-C 相当简单。 It's an iPhone app that probably doesn't use much in the way of OS-level UI.这是一个 iPhone 应用程序,可能不会以操作系统级 UI 的方式使用太多。 The C++ version is meant for a non-Apple platform where GNUStep is not an option, so Objective-C++ is not an option. C++ 版本适用于不能选择 GNUStep 的非 Apple 平台,因此不能选择 Objective-C++。

I worked on same problem.我解决了同样的问题。 And have some solutions:并有一些解决方案:

  • Microsoft now offers its own Objective C "bridge", albeit only for UWP apps. Microsoft 现在提供自己的 Objective C“桥”,尽管仅适用于 UWP 应用程序。

    https://github.com/Microsoft/WinObjC 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. 2007 年我尝试在 Visual Studio 中支持 Objective-C 并编写了自己的 ObjC 运行时,但我没有更多时间为它编写解析器。 If you have, you can:)如果你有,你可以:)

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

  • I wrote the basic functionality of Foundation Framework in C++.我在 C++ 中编写了 Foundation Framework 的基本功能。 In this case, you need to port manually;在这种情况下,您需要手动移植; your code will be on C++ but it will be like on Objective-C.您的代码将在 C++ 上,但它会像在 Objective-C 上一样。 This library worked on iPhone.这个库在 iPhone 上工作。

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

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. Objective-C 的动态特性很难转换为 C++,因此除了琐碎的 Objective-C 代码之外,还需要相当多的脑力劳动。 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)?您是否愿意继续使用 OS X(或者如果您是少数在 OS X 以外的操作系统上使用 Objective-C 的人之一,那么您是否愿意继续使用 GNUStep)? If so, the easiest approach is to use Objective-C++ to build a bridge beteen the Objective-C and C++ code.如果是这样,最简单的方法是使用Objective-C++在 Objective-C 和 C++ 代码之间建立桥梁。 Objective-C++ is an Apple extension to Objective-C and the GCC compiler that allows you to mix 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. 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.

Objective-C was just a pre-processor (and a runtime library). Objective-C 只是一个预处理器(和一个运行时库)。 You'll find more problems in porting all the libraries than the end-user code.在移植所有库时,您会发现比最终用户代码更多的问题。 Nil-eating behavior is going to be fun when translating.翻译时不吃东西的行为会很有趣。

You are likely to start seeing bad design in all c++ code after using Objective-C frameworks for a while.在使用 Objective-C 框架一段时间后,您可能会开始在所有 c++ 代码中看到糟糕的设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM