Making a Windows installer for a GTK Application

Cross compile the application in Linux with mingw

Assuming the necessary files and tools are in place (see below) then
$ ./configure --host=i686-pc-mingw32
$ make
Will cross-compile the app. Linking will fail, but can be done manually – see Hack1
Files used:
autogen.sh, configure.ac, Makefile.am – the standard Autotools files
hello.c – the program source
hello.exe – the program executable

Build the Installer in Windows in the wingtkapp folder

Build the executable as described above
Unzip the file GTK++RuntimeFiles.zip which populates the bin, etc, lib , manifest and sample folders with the necessary runtime files from GTK+ and its dependencies. It is created from the runtime zips at the GTK+ Project Page with version 2.16 of GTK+
Run file wixbuild.bat which builds the builds the msi from the following files:
Product.wxi, WinGtkApp.wxs, WinGtkRuntimeFiles.wxs – the source code for Wix
hello.exe – the program executable
This produces the following files:
WinGtkApp.msi – the installer itself;
– intermediate files WinGtkApp.wixobj, WinGtkApp.wixpdb, WinGtkRuntimeFiles.msm, WinGtkRuntimeFiles.wixobj, WinGtkRuntimeFiles.wixpdb. These files can be useful for debugging, but there is no need to keep or distribute them.

The installer can be run in Windows to install the software, either on the command line or by double clicking the file in Explorer. On the command line the syntax is:
msiexec /i WinGtkApp.msi
The software is installed in the folder C:\Program Files\Codethink\Hello App. The executable is installed in the bin folder with the GTK DLLs.

The software can be uninstalled either either on the command line or by the ‘Add remove programs’ control panel dialog. On the command line the syntax is:
msiexec /x WinGtkApp.msi
Uninstalling will remove the files and the \Codethink\Hello App folder tree in C:\Program Files unless files have been placed in those folders which are not part of the installation.

The file clean.bat removes all the generated files (including the installer)

Adapting for your GTK App

Edit the file Product.wxi, changing the variable defined there to match your application. GUIDs for your application can be obtained from here
Edit the file WinGtkApp.wxs:
– change all the GUIDs for new ones specific to your project – get them here
– add other files to be installed (manuals, readme, licence) See these pages for information on doing this in Wix
Tramontana’s Wix Tutorial
The Wix 3 Manual

Tools and System Requirements

1. The MinGW cross compiling environment]

Excellent tutorial here
Download the latest tarball
Extract to /Downloads/mingw-cross-env-2.19
cd Downloads/
sudo mv /opt/mingw /opt/mingw.old
mv mingw-cross-env-2.19 /opt/mingw
sudo mv mingw-cross-env-2.19 /opt/mingw
cd /opt/mingw/
make gcc
Go and make a coffee or two as this will take a long time!
Pay particular attention to Step 4: Environment Variables on the tutorial page. By exporting the two Environment Variables
PKG_CONFIG_PATH="entries for native builds"
PKG_CONFIG_PATH_i686_pc_mingw32="entries for mingw-cross-env builds"
from .bashrc,cross compiling should just work!

2. The Windows version of the GTK+ Stack

Available from the GTK+ Project Page, the all-in-one bundles of the GTK+ stack including 3rd-party dependencies. I used the 2.16 bundle. The files should be extracted to /opt/mingw/

3. A machine (or virtual machine) running MS Windows

I worked on a VM running a fully patched version of Windows XP Professional with Service Pack 3. Sadly, Wine doesn’t work.
The following additional software is needed in Windows:
– Wix ( Windows Installer XML) version 3.5 This is Microsoft’s open source tool for building WIndows Installers. Check that the bin directory is added to your PATH – the installer doesn’t seem to add it reliably. If it is not set then the calls to Wix components in the file wixbuild.bat will fail.
– Microsoft .Net framework. My VM had versions 1.1, 2.0, 3.0 and 3.5 installed. I encountered problems when trying to install and run Wix on Wine with version 4, but whether that was because of .Net or Wine I don't know. Alternatively you could try Mono GTK Sharp but I cannot vouch for it.

Notes and To Dos

1: The file wixbuild.bat uses the -sval argument when calling the light component of Wix to link the object files. This argument suppresses validation of the object files, and without it, the call will fail with the following error
light.exe : error LGHT0310 : Failed to open package for validation. The most common cause of this error is validating an x64 package on an x86 system. To fix this error, run validation on an x64 system or disable validation.
2: It should be possible to change the autotools files so that the program builds without resorting to Hack1