简体   繁体   中英

Can a desktop app be developed in C++ that would work on both Windows and Mac OS?

I am trying to save some money and develop a desktop application that would work on both Windows and a Mac OS. Is this possible? Can we do it in C++ and then, with a few fixes and tweaks, still reuse the same app on both OS?

Yes this is possible. Some code may differ as there are differences in the operating systems.

  • You should use a common library for GUI such as Qt: http://qt.nokia.com/
    It is worth noting that Qt brings much more cross-platform features to the table, so familiarize yourself with it.
  • There will be some differences to handle such as
    • File paths (C: doesn't exist on Mac, \\ and / are path separators, etc)
    • File endings differ (CrLf in Windows, Lf in Mac)
  • You need to compile to two different target CPU's. Most C++ compilers can do this.
  • The same code can be used for both, you just define regions to be (or not be) included depending on what OS the compiler is targeting.

Just Google a cross-os development guide, looooots of people has done this before. :)

It may not be relevant, but still worth noting (because you said "save money"), that both Java and the Mono Project (.Net, Qt) allows you to write cross platform applications with limited skills about the underlying platform. They are higher level language which in general are considered a time saver (but that is a separate discussion.)

Expanding on my comment:

Don't .

Write your library code in portable C++; putting as much as possible of the functionality in the library, making sure you study the platform-specific APIs (probably Cocoa and .NET) as you go, so the interfaces to the library are at least moderately suitable for either.

Then wrap your library in native binaries; ensuring that you pay attention to how applications are supposed to look on each platform, as well as the feel of them.

Building an application that looks like an X11 application and does everything in a manner somewhere between a Gnome application, a KDE application, an OS X application and a Windows application will really hurt user experience.

Badly .

WxWidgets

This question gets asked a lot , see also: this question , this one and this one amongst others.

Coming in late to the party here!

I'm in the last stages of finishing a cross-platform, commercial application (OS/X and Windows for right now, conceivably Linux or iOS later).

We're using an open-source, cross-platform C++ development library called Juce, and I can't speak highly enough of it. It's extremely full-featured, the code is solid and high-quality, and you can apparently build for Windows, OS/X, Linux, iOS and Android from the same codebase (we've only tried the first two, but other developers are apparently reporting success for the other platforms).

What's particularly nice is that lead developer is very active on his bulletin boards and extremely responsive to trouble reports.

Also, you can license the library under GPL, and they also have a very reasonably priced commercial license.

Juce is very popular amongst people doing digital audio applications - indeed, to my best knowledge many or perhaps most of the top commercial digital audio apps use this system - but it's very full-featured and extremely fast and should be considered a top candidate for any cross-platform development application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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