I write a lot of open source software that I make available on my website. How do I get my software compiled for all relevant platforms including:

  • Windows
  • OS X
  • Linux 32 bit deb
  • Linux 64 bit deb
  • Linux 32 bit rpm
  • Linux 64 bit rpm
  • etc

I currently only have Linux 64 bit boxes, so I can only compile the 64 bit deb and rpm myself. I'm relying on users contributing other versions. That isn't ideal because the versions are not all available right after a new release. Indeed the Windows binary is several versions behind at this point.

Edit: My software is QQWing. It is written in C++. I would love to have a build system that can generate binaries for all platforms, or have a place to run builds for multiple systems.

  • What language are you writing in? – raptortech97 Sep 29 '14 at 13:30
  • 1
    So what is your problem? Maintaining the build system or actually running the builds somewhere or what? And what build system and what language? – Jan Hudec Sep 29 '14 at 13:31
  • 6
    With great difficulty. – John R. Strohm Sep 29 '14 at 14:00
  • 1
    This question is very broad, can you narrow it somewhat? – M. Dudley Sep 29 '14 at 14:28
  • 2
    1) Can you cross-compile? I believe that should be possible at least for different linux flavours. 2) Compilation is usually the easy part. Debugging platform specific issues is the main problem. – CodesInChaos Sep 29 '14 at 14:47

Any professional organisation would have not just build machines but test environments for all those platforms they support.

And that's why most professional organisations won't support such a plethora of platforms, it's just too expensive for the small return that each of them yields except the few big ones like for example Windows, Mac, and RedHat based Linux.

So you'll have to get the hardware to run all those operating systems, the compilers and other tooling for all of them as well. Or maybe you can get away with running all those OSs in virtual machines, if your hardware is up to the task.

  • I find it hard to believe that that is the solution that most software projects use. There has to be an easier way! – Stephen Ostermiller Sep 29 '14 at 14:45
  • 1
    The easier way is to run Windows, Linux and OS X from a Mac. – mouviciel Sep 29 '14 at 15:41
  • 2
    @StephenOstermiller, I don't know what most projects use, I do know that in the 20 years of my career we always had computer farms with a set up so that we could run tests on all supported platforms and we would never deliver something to our customer which had not passed the tests (or at least had to failure waived out). – AProgrammer Sep 29 '14 at 16:13
  • 1
    @StephenOstermiller there is no easier way. There might be a cheaper way, which is much more cumbersome, more error prone, slower, etc. etc., but no easier way. VMs are one such, cheapish alternative to more hardware (and yes, that's what you can do on a Mac, run VMs, just as you can on Windows, Linux, and a lot of other operating systems). Wishful thinking isn't going to make something appear out of thin air just because you don't like it that the actual realistic solution costs money. – jwenting Sep 30 '14 at 2:04
  • Even when I was running my 1 person shop writing software for Windows and macOS, I bought the hardware and software to do builds for each. – user1118321 Mar 27 '18 at 3:29

Part of software development is managing complexity. By specifying multiple output targets, you are adding complexity. Asking that there "must be an easier way" in this case is a bit like the Simpsons episode where the lady asks "put all the groceries in one bag, and don't make it heavy!".

If you have complexity, sometimes it's better to manage it correctly, rather than trying to reduce it.

One solution would be to use Vagrant to define a virtual machine specification for each of your target platforms. This would include OS, compiler, and whatever other tools are required.

Then, use a build tool such as Jenkins, TeamCity, Bamboo, etc. to to create build plans for each of your platforms. Link these build plans to your source repository (this is basic CI, and execute them all when changes occur.

Now, you not only have multi-platform support, but you have a build process that both works, and is self-documenting. This way, you don't have the issue where you spend a bunch of hours configuring a real machine to build on Windows, then when the hard drive fails six months later, you've forgotten how you got it all working, and have to start over.

  • Vagrant sounds promising. Are there tutorials that show how to set it up for a bunch of different environments? Are there versions of Windows and OS X that it can bring up with gratis licensing? – Stephen Ostermiller Sep 29 '14 at 17:00
  • @StephenOstermiller The documentation on the Vagrant side is reasonable, but I'm sure you can find tutorials to fill in the gaps. There are two approaches to creating a Vagrant VM: one in simply to make a VM on VirtualBox, VMWare, etc., and specify that image as the source. The other way is to add provisioning steps to the Vagrant file that define how the VM should be configured (on top of the base OS). I prefer this method, since the file (with the steps in it) can be checked in and easily modified. It does add some load for end users though when they bring up your machine for the first time. – Dan1701 Sep 29 '14 at 17:08
  • 1
    The OSX license forbids running OSX on anything other than Apple hardware (with the exception of OSX Server, I think, which is allowed to be run in a VM, as long as that VM is in turn running on Apple hardware). In Germany, such restriction are illegal, so you could run OSX in a VM in Germany. Note that you will still have to buy OSX, though. – Jörg W Mittag Sep 29 '14 at 23:14

GCC is able to compile both 32-bit and 64-bit on the same machines using the -m32 and -m64 flags, respectively (source). Of course, your code should also be tested to make sure there are no bugs introduced between 32 and 64 bits.

You can cross-compile your code into a Windows executable using Wine libraries. The mingw libraries provide compilers that act similarly to gcc, while outputting a Windows-compatible (technically a Wine-compatible) binary. You could have a command like i586-mingw32msvc-gcc -Wall "main.c" -o "Program.exe" to compile your program (source). There are differences between Wine and Windows, so there may be subtle and unexpected bugs from using this method. Once again, thorough testing is critical.

You can see the answers at this SO question for suggestions on how to compile for the Mac.

Disclaimer: I've never used any of these in a production capacity, so YMMV.

Not the answer you're looking for? Browse other questions tagged or ask your own question.