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.
9
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.
5
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.
1
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.
3