如何将 Cocoa/Mac 应用程序移植到 Windows?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2062536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:45:01  来源:igfitidea点击:

How do you port a Cocoa/Mac application to Windows?

windowsmacosport

提问by Ron

How do you port a Cocoa/Mac application to Windows? I mean how would you go about it? Assume the app was written with Objective-C and Cocoa, there's nothing fancy going on, no "engine" that could be factored out, etc.

如何将 Cocoa/Mac 应用程序移植到 Windows?我的意思是你会怎么做?假设应用程序是用 Objective-C 和 Cocoa 编写的,没有什么花哨的东西,没有可以分解的“引擎”等。

Rewrite from scratch? I don't think there will be huge overlaps between the Mac and Windows codebases, right?

从头重写?我不认为 Mac 和 Windows 代码库之间会有很大的重叠,对吧?

采纳答案by Yann Ramin

The problem with Objective C is its very poor support on any platform that is not OS X. You can attempt to use the Cocotron, but I wouldn't consider it production ready yet.

Objective C 的问题在于它在非 OS X 的任何平台上的支持都很差。您可以尝试使用Cocotron,但我认为它尚未准备好生产。

For portability, a re-write is in order. With judicious use of standard C or C++ for the "core" of the application, you could still implement platform specific GUI code. If you don't like maintaining two GUIs, you can also try a toolkit such as Qt

为了可移植性,重写是有序的。通过明智地将标准 C 或 C++ 用于应用程序的“核心”,您仍然可以实现特定于平台的 GUI 代码。如果不喜欢维护两个GUI,也可以试试Qt等工具包

回答by Chris Becke

I have doubts about cocotron. Its not clear from the cocotron website that cocotron is actually production ready yet. Id suspect that it would be possible to start new app development and use cocotron constantly to maintain and test windows builds on the go. But to retrofit it into an existing project might be a much larger task. There are also no alternatives to cocotron - other than perhaps gnustep.

我对 cocotron 有疑问。从 cocotron 网站上还不清楚 cocotron 实际上已经准备好生产了。我怀疑有可能开始新的应用程序开发并不断使用 cocotron 来维护和测试 Windows 构建。但将其改装到现有项目中可能是一项更大的任务。除了 gnustep 之外,也没有 cocotron 的替代品。

The practical approach to cross platform development involves developing the non gui components of your application, once, in C or C++. And then using a cross platform GUI library like QT - which is VERY good at generating and using native UI where possible or faking it where not. Please DO go to qt.nokia.com and download the latest build of QTCreator for windows and mac - See how the same QT application looks and feels very convincingly native on both platforms.

跨平台开发的实用方法包括在 C 或 C++ 中开发应用程序的非 gui 组件。然后使用像 QT 这样的跨平台 GUI 库——它非常擅长在可能的情况下生成和使用本机 UI,或者在可能的情况下伪造它。请访问 qt.nokia.com 并下载适用于 windows 和 mac 的最新版本的 QTCreator - 看看相同的 QT 应用程序在两个平台上的外观和感觉如何非常令人信服。

If QT doesn't provide a native enough solution, then you need to develop your GUI twice :- once in Cocoa, and once in Win32. The cocoa GUI would be in objective C of course, the Win32 GUI in C/C++.

如果 QT 没有提供足够原生的解决方案,那么您需要开发两次 GUI:- 一次在 Cocoa 中,一次在 Win32 中。Cocoa GUI 将在目标 C 中,Win32 GUI 在 C/C++ 中。

Your non gui application code would - written in c++ - not be able to call Objective-C directly, but its not hard to write shim classes, implemented in .mm files - the provide a c++ interface, and wrap access to an objective c object or class.

您的非 gui 应用程序代码将 - 用 c++ 编写 - 不能直接调用 Objective-C,但编写 shim 类并不难,在 .mm 文件中实现 - 提供 c++ 接口,并包装对目标 c 对象的访问或班级。

You are also going to have to come up with an alternative to CoreData on windows - perhaps sqlite? Given that XCode has integrated support for the sqlite framework, and testing multiple code paths is, well, more work - perhaps dropping CoreData in favor of a common layer is a better approach?

您还必须想出 Windows 上 CoreData 的替代方案——也许是 sqlite?鉴于 XCode 已经集成了对 sqlite 框架的支持,并且测试多个代码路径是更多的工作——也许放弃 CoreData 以支持公共层是更好的方法?

回答by Cooper6581

Depending on which objects and framework you are using for your cocoa app, you might be able to get away with using gnustep, although the end result will probably look very weird to windows users, and the development environment might be a bit difficult to setup at first.

根据您用于可可应用程序的对象和框架,您可能可以使用gnustep逃脱,尽管最终结果对于 Windows 用户来说可能看起来很奇怪,并且开发环境可能有点难以设置第一的。

回答by EightyEight

Are you aware of Cocotron? It looks like the project may have gone stale, but it's a good starting point anyway. It's a project to port Core APIs.

你知道Cocotron吗?看起来这个项目可能已经过时了,但无论如何这是一个很好的起点。这是一个移植核心 API 的项目。

If your application is not cleanly separated (ie: a la MVC) then the only solution is a rewrite, I think.

如果您的应用程序没有完全分离(即:a la MVC),那么我认为唯一的解决方案是重写。