I’ve been playing with cross-compiling Windows programs on Linux using Fedora’s build of MingGW.

Part of the Fedora build is nsiswrapper, which is a Perl script wrapper around the NSIS opensource Windows installer maker (like makeself on Linux) from Nullsoft, the creators of WinAmp. The wrapper doesn’t work very well with Qt4 as it runs lc() on all its dependency filenames, and Qt4 is heavily mixed-case like QtGui4.dll and QtCore4.dll, so I just created a .nsi file myself.

NSIS is really badly documented, and I’ve already discovered a few oddities when using it with Windows7, such as not removing start menu shortcuts properly, which can be fixed using this snippet in the .nsi file:

RequestExecutionLevel admin

Section "Start Menu Shortcuts"
  SetShellVarContext all
  blah....
SectionEnd

Section "Uninstall"
  SetShellVarContext all
  blah....
SectionEnd

I also found that to get the program listed in Add/Remove Programs, you have to set a few Registry values:

Section "Hello World"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HelloWorld" "DisplayName" "Hello World"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HelloWorld" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HelloWorld" "Publisher" "Simon"  
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HelloWorld" "DisplayVersion" "0.2"
SectionEnd

Another part of the Fedora build of MinGW is windres, which handles things such as inserting icons into the executable, first you create a resource file then you have to build it and pass the resulting object file into the qmake command:

i686-pc-mingw32-windres resource.rc -O coff -o resource.o
qmake-qt4 -project
qmake-qt4 -spec win32-fedora-cross QT_LIBINFIX=4 OBJECTS=resource.o
make

Oddly enough the qmake spec file /usr/lib64/qt4/mkspecs/win32-fedora-cross/qmake.conf is configured for console applications, so to get rid of the DOS box for a Windows application, you have to change the QMAKE_LFLAGS line:

QMAKE_LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import \
   -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,windows

The included snippet doesn’t work unless you’re building on Windows itself it seems:

QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows

You can find the required DLL’s for a package using another part of the MinGW buildsystem which is essentially a wrapper around objdump:

i686-pc-mingw32-objdump -p hello.exe | grep dll

After running makensis you end up with a Setup.exe which installs your program and required DLL’s, shortcuts and uninstall info, it will even run under WINE with a few modifications.

Update: I’ve been trying out Qt Creator, holy moly that’s a nice IDE – not only are Designer, Qmake, Assisstant, Linguist etc. properly integrated, but the C++ sourcecode editor is very nice too, with Qt-specific hints, code folding, syntax highlighting etc. You can even integrate the mobile application SDK and smartphone emulator.