HOWTO: Cross-compile a Go app for Windows from Linux

I recently needed to test some app on windows, and while cross-compiling in Go is straight-forward, the app had some C code and apparently on Arch Linux the mingw64-gcc package is misconfigured.

After some head scratching I figured out a workaround until the package is fixed (task #4313), you have to link your Go code against ssp.

note this bug is specific to Arch Linux, however other distros might build the toolchain in the same manner.

Building the toolchain:

1. Download and unpack the Go source code:

note this guide assumes $GOROOT is set to /usr/src/go/.

  • Use mercurial (slow) hg clone -u release
  • Use the source tarball from

1a. (optional but recommended) add export PATH="$PATH:$GOROOT/bin" to your ~/.bashrc (or the equivalent file for your shell).

2. Compiling the native toolchain:

3. Compiling the Windows toolchain without CGO:

Repeat with GOARCH=amd64 if you want to build win64 binaries.

4. Compiling the Windows toolchain with CGO support:

  • Install mingw-w64-gcc

Repeat with GOARCH=amd64 CC_FOR_TARGET="x86_64-w64-mingw32-gcc .... if you want to build win64 binaries.

note that once the bug is fixed, you can remove -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp from CC_FOR_TARGET.

Actually compiling your code to run on windows:

We use the same environment variables from earlier, except we have to replace CC_FOR_TARGET with CC



note that to build native go with cgo you will have to use env CC=gcc go build

Using CMake + Mingw to Cross-Compile Windows Apps (Part 2)

this is deprecated and have been long replaced by the mingw-w64 packages.

As promised, here's the second part of the tutorial on how to use cmake to build Qt4/OpenSSL Apps for Windows using mingw on Linux.

Assumptions :

1. You already followed the tutorial on how to setup Qt4/OpenSSL using mingw.
2. You have cmake installed.
3. You have a working wine setup or a way to test the executables.
Continue reading

Crosscompile Mingw + OpenSSL + Qt4 for Windows on Linux

this is deprecated and have been long replaced by the mingw-w64 packages.

For the longest time I used Mingw + cmake on top of wine to cross compile my Qt4 apps for windows, then I was bored one day, tired of how slow it is to recompile qt4 on wine and decided to try to get it to work with a native gcc instead of the overhead with wine.
So here goes.

This was done on Gentoo Linux, please don't ask me how to do it on other distros.

Assumptions :

1. You know your way around the linux shell and have portage privileges.
2. You're not scared from compiling things by hand.
3. You already have Qt4 installed and it is the same version as the windows source we gonna build.
4. Your working path will be ~/win32.
5. You have a working wine setup.
Continue reading