How I use Linux to write software for multiple target platforms

This article has everything to do everything with Wine - a pure magic that makes it possible for native Windows executables to run on POSIX compilant operating systems like Linux, MacOS or BSD. Just if you don't know about Wine yet, read about it:
In short: wine runs windows programs on Linux, MacOS and BSD, and it does not use virtualization or any sort of emulation. 

If you cannot or do not want to target Linux but you are targeting Windows, the least you can do it to make it wine compatible. 
If your Windows software works under wine, I will pay for i to use it on Linux. 
As far as Linux users are concerned, you already are targeting them too, when you remember about wine.

While I do not know much about popularity of it on MacOS or BSD, I dare to claim that it is truly widely used by Linux desktop users. Also, it probably is most tested and most stable with Linux, although theoretically it can be supported by any POSIX compilant OS.
For this reasons I want to make a claim in this article, that wine makes Linux the best host operating system for multi platform software development. That it is easier (conditions apply) to target multiple platforms (especially Linux, MacOS and Windows) from a Linux host than from any other of the two because:
  1. If your SDK only comes available for Windows, you can still target Linux and even MacOS with it.
  2. If your SDK does come for both Windows and Linux, as long as the Windows version is wine compatible it is much easier to target both platforms with it from a Linux host than from a Windows host.
  3. If your Windows-only SDK is wine compatible, from a Linux host you can also target Linux and MacOS with it.
And since Ubuntu is reportedly the most popular of all Linux distributions on desktop (in terms of number of users), and since it is the operating system that I mostly use, therefore everything that I will cover in this article, and all of the claims I will be making about Linux, will at least apply to Ubuntu and should in theory also apply to other Linux distributions with possible differences in details. For the most of the following content I will narrow my focus down to Ubuntu Linux and Windows, but I'd like you, the reader, to remember that what will be true for Linux would mostly also hold true for other platforms supporting wine, especially MacOS or BSD.

Because of my personal preferences in my examples and demos I will be using Pascal language compilers and IDEs. However, you can find general concepts also valid for your preferred programming language, compiler or SDK. Also, I have previously posted another article which talks about targeting multiple platforms with pascal: 
This article will be broken into three parts, each featuring a demonstration video:
  • SDK available for multiple platforms natively, and the windows version is wine compatible
  • SDK only available for windows natively, and it is wine compatible
  • SDK only available for windows natively, and it is not wine compatible
My demo projects for this article will demonstrate a rather unconventional approach, so please make sure you understood the claims in each chapter. I really want to go outside of the box this time, and show some extremely alternative (but fascinating IMHO) ways of multi-platform programming.


SDK available for multiple platforms natively, and the windows version is wine compatible

Although a native SDK exists for both Linux and Windows, it is easier to target both platforms from a Linux host than from a Windows host, when the windows version of the SDK is wine compatible.
On windows host, you would need some sort of virtual machine or emulator running Linux with a native linux SDK installed there. You would also need to either mount a host directory with the source under your guest system or you would need to copy source from host into the guest for compiling for Linux.
On a Linux host, however, no virtualization or emulation would be required. You could have both the native Windows and the native Linux versions of your SDK installed directly on your host and you could run them simultaneously side by side.
To demonstrate this scenario I will use the example of Lazarus, a Delphi-like IDE written in Free Pascal and using it as its compiler. Lazarus is available natively for both Linux and Windows, as well for many other platforms, also including MacOS. You will see that it is possible and easy to write Windows software on Linux.


SDK only available for windows natively, and it is wine compatible

If your SDK is not available natively for Linux, but its native Windows version is wine compatible, then having it installed under Linux makes it easier for testing and debugging. Easier because you do not need to go into a virtual machine with a Linux guest system to test it, you would just test it directly on your host for both platforms all at once.
To demonstrate this scenario I will be using Borland Delphi installed directly on Linux. I have personally tested Borland Delphi versions 3,5,6 and 7, and all of them do install and work well on Linux under wine. I have checked for "Delphi" on the WineHQ App Database though, and it lists even Delphi XE8 as usable (with some extra steps). Reportedly, however, Firemonkey does not work. On the other hand the Delphi 6 is listed as not really usable (labeled "Garbage") yet I had plenty of success installing and running it. So I leave this up to your judgement and will to experiment.
The demo that I will show you is somewhat surprising, so please try to wrap your head around it:
I will use Windows native Delphi IDE to create a windows native program, dedicated solely with a purpose of using it in Linux - not Windows - for it will list old kernels and allow user to uninstall selected ones to free up space on the boot partition. And I will do all of this in Linux. 
In other words, I will create a program for Linux, on Linux, but using windows native Delphi IDE and the program itself will be a Windows executable. And it will have no use under Windows, except that it will start and alert you that it is not design for using on Windows but on Linux only. 
This video below is a proof of concept that you can in fact write Linux software on Windows, and as a twist, that you can also write Windows software for Linux on LinuxMind blown?? Well, enjoy the video then.


Presented in the above video UKM is a Borland Delphi 7 written project of a Linux tool for listing and removing old Linux kernels for recovering disk space on /boot partition. The project compiles into a Windows native binary EXE file, but is meant to be used in Linux, and serves no purpose when executed in Windows. Here is the full source code in Object Pascal (Delphi): UKM.7z

Below is a screen captured of the program UKM.exe running in Ubuntu Linux. The Program window lists kernels found on the system, and allows user to select any. Currently used kernel is marked in bold font. When user selects a non-current kernel, the button under the list becomes enabled, and user can hit it to uninstall selected kernel. A gnome-terminal window will open, asking user for root password, and then will uninstall the kernel. I emphasize, this is a windows EXE file running in Ubuntu Linux, and in the lower text field of the program window, there is an information about the host system. That information would not be retrieved if the program was executed natively in Windows, nor would it's functionality be available:

This source code has no special license, let's say I am making it a Public Domain, feel free to use it however you wish, but do not hold me responsible for any damage from using it, nor expect any support on this code, as it is just a quick proof of concept meant as a educational material. Use it however you want, at your own risk.

SDK only available for windows natively, and it is not wine compatible

If your SDK is only available natively for Windows, and it does not install/run under wine, then you can still use it to produce wine-compatible and wine-aware software. In this scenario you would most likely either need a Linux virtual machine on a Windows host to test your application, or a Windows virtual machine on a Linux host to write your application, then test it on the host.
I would still prefer the later from the former, because as a software developer I might either currently or in the future be using other SDKs some of which might either be available natively for Linux or have native Windows versions compatible with wine. But I do admit that in this special scenario my preference for Linux is very subjective.
To demonstrate this scenario I will use Delphi XE10.1 Berlin, which does not support Linux at all as platform target, and I will under Windows write a Firemonkey GUI application serving the very same purpose as the demo from the previous chapter. Windows native executable which in fact is a a program for Linux for listing and uninstalling kernels. The only difference with the previous demo is that this time I will write the program on Windows, and then use on Linux. Enjoy the video!

(to be added)


  1. How I use Linux to write software for multiple target platforms? Answer is very simple - Use Qt framework :)

  2. Just don't sell wine-wrapped software as a complete Linux port.
    And as @porterneon mentioned, a cross-platform framework is always better (and Qt is awesome).


Post a Comment

Popular posts from this blog

Lazarus IDE on ARM Ubuntu (Raspberry Pi, Ubuntu Touch, etc)

SSH and Ubuntu Touch - everything you want to ask but are afraid to ask

Console vs GUI application in Object Pascal - is it either-or?