DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on


Cross compilers, native compilation, or some kind of VM (like Java)?

Of course, JavaScript with web browser is also a VM, but it cannot access filesystem, and much less powerful than JVM.

Docker is probably not an option, when distributing desktop apps to end-users.

So, if cross compilation, what is your toolset and language of choice? I realized I can cross-compile Go with xgo (which supports all three major platforms), and Rust with cross (which does not support macOS). I have no idea how to do C/C++ directly.

Not sure if Python, how do you link for the different platforms you are not using?

I also realized that it might be possible to compile semi-natively via Docker with WINE, which is again, cannot target macOS. - Electron Builder can also use this method.

Don’t expect that you can build app for all platforms on one platform.

Another safe way is to use Java or JVM, but how many (non-dev) people actually installed JRE these days?

Lastly, if you use native compilation, how often do you have to open other OS's. I can open Windows in VirtualBox, but I yet to have access to Hackintosh (i.e. macOS).

And yes, I do realize that I can compile on CI with both Windows (which has Visual Studio) and macOS (which has Xcode) as well; but I don't have much experience on that.

Top comments (6)

cacilhas profile image
Arĥimedeς ℳontegasppα ℭacilhας

I’ve understood you wanna develop desktop applications for final user, am I right?

There’s no final answer, all I can do is telling you my feeling.

I won’t incite you to do cross-compilation, but it’s not to discard.

C/C++ are cross-platform if you code properly. For instance, using Qt, C++ becomes a whole other language, that you can compile for Linux, BSD, macOS, and Windows virtually with no changes.

Python runs over a VM too, called CPython. If you avoid system-coupled data, a Python application potentially can run over Linux, Windows, and so on. Take a look at os module and its os.path submodule.

Finally the JVM is always a fail safe.

chand1012 profile image

The issue with supporting all three of the major platforms (Linux, Windows, macOS) is that without using CI/CD with unit testing you're going to have to try and run the program on all of the systems. This is why when I do attempt to write a program that is supposed to run on multiple OSes I tend to leave out macOS as I don't have access to an OSX machine nor an easy way to create a VM for macOS. I have in the past made a macOS VM on my laptop but that took days of tinkering and is very frowned upon by Apple. Plus, assuming you don't do any tedious workarounds, you absolutely need an Intel processor to get it up and running.

In my opinion, the easiest way to create cross-compiling/running apps with little in the way of issues with OS compatibility is probably going to be Java, or something similar. You are allowed to bundle a JRE with your application (provided you meet Oracle's TOS or decided to use an open source alternative like OpenJDK), and there are still a great deal of users who still have a JRE on their computers. This is assuming they would have another application that requires it, which if they're running older software is definitely the case. Plus, if a GUI is needed, Java has a few cross-platform libraries available for that. Finally, you could go the old fashioned route of just saying "You need to have a Java installation to run this program".

Python isn't a bad choice, but packaging the application is a pain, because like Java, it needs a way to run. Now you could go the intermediate route and run Python on the JVM with Jython, but unless a library is written in pure Python, or you end up just using Java libraries, you're going to be limited as to what you can use to write your application.

If native is a requirement, I think Go would be the best option. You can easily cross compile for basically any platform, and most of the popular Go libraries had cross compatibility in mind when they were written. The issue is going to be with GUIs. This is because, while Go has plenty of cross compatible libraries, there is only a handful of underdeveloped cross platform GUIs. If this program is command-line only anyway, I'd write it in Go.

Finally, what I would actually do: Don't distribute an application to the user at all. With how the world of development is going and how the web is evolving I think that desktop applications are dying, with exceptions. Video games (contrary to what everyone is trying to tell us) will still be native, there are plenty of scientific computing, engineering, software development, among many others, that would require access to the operating system or the user's hardware. Unless you absolutely need access to a regular end-user's hardware or operating system, most people are going to be just fine with using said application in their browser, "on the cloud" as the marketing teams say.

Sorry for the speech, just thought I would put in my two cents.

lmtr0 profile image

Firstly, The cross compiler that support macos for linux is osxcross and you can easly put it inside a docker container to use it inside windows. for targeting cross-compilation with rust you just need to change the assembler and the linker for each platform that you want to support, In my case I'm on linux so I use mingw64 for cross compiling for windows and osx-cross for macos. here you have clang for linux and osx and mingw gcc for windows, you also have gcc for linux if you are into it. this shows how to implementing it in a existing rust project

slavius profile image
Slavius • Edited

Actually C++ with Qt Framework is used surprisingly often to deliver cross platform apps.
Another choice (despite less frequent) is .Net Core (cross platform) with Avalonia UI.

Top Heroku Alternatives (For Free)

>> Check out this classic DEV post <<