Compiling Windows binaries on Linux

less than 1 minute read

The idea is how to setup your Linux box to compile your code for the Windows platform using MinGW. Depending on your distribution, the installation of the needed packages can differ.

Installing Mingw

Ubuntu 7.10

Install the mingw package from the Universe Repository, using synaptics or with the following command:

sudo apt-get install mingw32

Example Usage

Once installed, save the following file as hello.c (stolen from Installing and Using the MinGW Cross-Compiler on Mac OS X):

#include <windows.h>
int main(int argc, char *argv[])
{
    MessageBox(NULL, "Hello, world!", "Hello, world!", MB_OK);
    return 0;
}

To build the example, execute the following command:

i586-mingw32msvc-gcc hello.c -o hello.exe

and run it, for example, with wine: wine hello.exe

Categories:

Updated: