Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 618
Joao Azevedo Avatar asked Dec 19 '25 17:12

Joao Azevedo


2 Answers

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.)

like image 179
Tedd Hansen Avatar answered Dec 21 '25 07:12

Tedd Hansen


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.

like image 22
Williham Totland Avatar answered Dec 21 '25 07:12

Williham Totland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!