Create a cross platform Windows, Mac OS X application

浪尽此生 提交于 2019-11-28 14:40:16

问题


I would like to build an application that runs on both Windows and Mac OS X. I would also like it to leverage the best of what the platform it runs on has to offer with regards to Frameworks, API's etc. Is there a way to do this without having to write Objective-C code and then C# code? I've been thinking of C++ as an alternative but I was wondering if there was anything else out there. The app will be GUI based (though I don't know exactly what it will do yet)

-G.


回答1:


It's good that you're thinking of portability early on - it's vastly more difficult to "bolt it on" after the fact.

There are various cross-platform kits available, but IMHO all of them fall a bit short of providing a "native" look and feel on all the supported platforms. On the Mac (what I use), proponents of such kits always want to mention that they're using native controls. That's a good start, but it's not the whole journey. Other issues addressed by Apple's Human Interface Guidelines include how the controls should be arranged, how button labels should be phrased, what standard shortcut keys should be used, etc.

Even Microsoft had to learn the hard way about the dangers of trying to write a cross-platform GUI, with the ill-fated Word 6.0 for Mac.

IMHO, a better approach is to use an MVC design, with the model layer written in standard, portable C++, and the view and controller layers using the native toolkit for each platform. For the Mac version, Carbon and C++ throughout used to be an interesting option that is now not supported anymore, so you would want to use Cocoa, using Objective-C in the view and Objective-C++ in your controllers to bridge the language gap. Your Windows version could likewise compile your model as "managed C++", and use any .NET language for controllers and views.




回答2:


Take a look at Real Studio. Seriously. You can write an app in Real Studio and deploy it on Windows, Mac OS X, and Linux.

Edit: Real Studio is now Xojo.




回答3:


wxWidgets is a cross platform C++ library, which is a practical choice. But I agree with Sherm - all cross platform libraries do create an inferior UI to native applications.

It's made harder by each OS having different UI semantics (button orders etc), so while you may achieve a good look, getting the 'feel' right on each platform via one view layer is almost bound to be impossible.

Depending on what you end up doing, you may find a web interface better (e.g. embed a web server in your app and serve HTTP pages to a browser). You avoid the L&F issues then!

Alternatively, you can decide you're just going to have a completely non-standard L&F, and go for something like wxWidgets, or Tcl/Tk.




回答4:


Adobe Flex, with the AIR libraries, does a good job of giving you a single, highlevel development environment for this sort of thing. I've written several utilities that people use on both platforms interchangeably.

You also get reasonable portability to a browser thrown in, too, if that's of interest. But I think it's a pretty good solution without considering that benefit.




回答5:


My suggestion, use Python. Python integrates with both Objective-C and C# (IronPython). Just avoid a lot of the brand new bleeding edge features of the language and you're ok.

Granted, it won't be mindlessly easy. But I'd argue that it shouldn't be mindlessly easy. It becomes very apparent when designers don't take into consideration how their application will work when it gets ported to another platform.




回答6:


For the GUI, I'd look into SDL or QT.

Also, check out mono http://mono-project.com/Main_Page




回答7:


If you do decide to go with C++ there are a number of good cross-platform GUI libraries that will allow you to avoid having to duplicate the GUI code for each platform. For example:

  • Juce
  • QT
  • wxWidgets

There are a number of other similar projects but those are some of the better and more well-known ones. For the remainder of your code, anything system-specific will of course have to be written using separate C++ code to interface with Win32 APIs or OS X's system API where necessary. That being said, you may find you're able to avoid much of the system-specific code by using extensive libraries like Boost.

Other suggestions would be things like using a configuration file instead of the Windows registry or a plist file on the mac. Instead, shoot for platform-agnostic approaches wherever possible to minimize the places where you have to write code using system APIs.




回答8:


You should use the best tools available for each OS.

C/C++ code can be separated from the GUI and used in each separately developed program.

Before you make a decision, take a look at cross-platform apps that have been developed with portable toolkits such as Qt or wxWidgets. In my experience they are never as polished as their native counterparts, especially on the mac.




回答9:


The upcoming QT-Creator might be worth a look: link text




回答10:


If you're a Windows developer, use either Qt or C# Winforms; if you're a Mac developer, you could try Cocotron (http://www.cocotron.org/), but it's not 100% finished yet, though commercial apps have been shipped with it.




回答11:


thanks for all your answers. I've been doing some research and playing around with WPF and CAnimation etc. It looks like using a C/C++ model and doing the GUI individually for each platform is the best way to go. Thanks for all your help.




回答12:


Also check out fltk , wxWidgets is very good & rich but also very big...




回答13:


As others have mentioned is is definitely possible to create good looking cross platform GUI in Java on both Windows and Mac. However if you want your app to blend in and behave in a way that makes it "feel" like an application designed from the ground up for the platform it is running on, you really have to develop the GUI and user experience for each version of the application separately.

If you analyze what your application is going to do and figure that there is a significant portion of code/logic that could be shared between platforms then write that portion in a portable way in a language that is available on both systems. C, C++, Java, Python, Ruby, etc. If there isn't a significant portion, ie most of the code is going to be for the GUI then there is less of a case for sharing any code at all.

In the case that there is a significant portion of common code, I would suggest looking into Python and Ruby as implementation languages as there are Cocoa bindings for those languages on the Mac and on Windows with the use of IronPython and IronRuby you could use reuse that code in a .Net application as well.




回答14:


As long as you are not tied to languages, it looks like Java is a good candidate. Pair that up with SWT for the GUI, and you will have a native looking app on any OS you like.




回答15:


I'm planning to do a similar thing, and I'm considering creating a C#/.NET Windows application and then porting it to OS X using Mono. My application already has a completely (except for the title bar and corner buttons) custom-drawn user interface, so the cosmetic OS differences shouldn't affect me too much.

I'm not sure what you mean by leveraging the best of each platform in terms of frameworks and APIs and so forth. In general, writing a cross-platform application means writing to a least common denominator, and thus means not getting the best out of each platform.




回答16:


Java or Mono come to my mind. Some people may argue that java graphical toolkits are not the cuttest out there but it seems to be, at least to me, the easiest way to port your application to several platforms and avoid deployment difficulties.

Mono, on the other hand, could be a little bit more difficult to port as you would have to write at least the gui twice if you plan to have native widgets (either winforms or GTK for windows and CocoaSharp for Max) but you could write the backend only once and develop a frontend for each platform.

As I said, Java GUI toolkits might not feel "native" inside OSX or even on Windows but they sure work on both platforms, you could use either Swing or AWT.

As for mono, you can use GTK or Winforms for both windows and OSX but they still will not feel native, you can, however use CocoaSharp which are bindings to the Cocoa framework but Im not sure about the status of the project (read: functionality support)




回答17:


I second Java. It is designed as a cross-platform solution.

Others have mentioned Adobe Air.

Similar to Adobe Air is Silverlight. I believe it is (or will be) completely cross platform.




回答18:


You can create fantastic looking cross platform applications with Java Swing. It just requires slightly more effort to learn to do so.

Here, take a look at some of these links.

  1. http://jidesoft.com/products/component.htm
  2. http://www.xerto.com/imagery.php
  3. http://www.jgraph.com/screenshots.html
  4. http://www.javootoo.com/
  5. http://www.formdev.com/screenshots/
  6. http://www.jidesoft.com/products/oss.htm



回答19:


The guys at Magnetism Studios have a nice write up on using Cocotron to build a Windows executable with Xcode.

I have no experience with Cocotron, but if I needed to write a windows app —with a Mac development background— this would be the first thing I'd try.




回答20:


If you choose C++ language, I would definitely recommend Qt for that. Your application can be deployed under Windows and Mac as requested in the OP, but also Linux, and now, with the latest version on smartphones using iOs, Windows RT and Android.

It's well documented and very active on the web (including on SO).

The only negative point I see is Qt creator tool which, IMHO, is less user friendly than historical tools (like Visual Studio for instance ), but you are not actually forced to use it as an IDE for Qt development.




回答21:


For completeness, it's now worth adding Unity to the list.

It would be very hard to create a native-looking app for either platform and the general GUI tools are far from mature. But, it's not just a game engine and you can write in C#/Mono, make use of a decent range of libs and deploy to Win and OSX fairly painlessly.



来源:https://stackoverflow.com/questions/252514/create-a-cross-platform-windows-mac-os-x-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!