Cross Compile to Windows From Linux


For Crossmeta FUSE (File System in User Space) that uses projects  mostly written for Linux platform that depends heavily on GNU tool chain, it will be quite challenging to adapt to Microsoft Build environment. I have been using the DDK BUILD environment even for building Win32 programs that are not drivers and it uses single MSVCRT.DLL for C Runtime library . This has miraculously saved me from the MSVCRT.DLL versioning nightmare that Visual Studio developers were long facing.  Here is the list of those versions and now there is Universal CRT to seal it off.

  • MSVCRT70.DLL Visual Studio .NET
  • MSVCRT71.DLL Visual Studio 2003
  • MSVCRT80.DLL Visual Studio 2005
  • MSVCRT90.DLL Visual Studio 2008
  • MSVCRT100.DLL Visual Studio 2010

So the DDK build is a decent build environment for Crossmeta project with multiple directory levels and it came with its own compiler and linker to finish it off. Lately Microsoft abandoned this BUILD tool and forced everyone to switch to new MSBUILD environment.  The Windows DDK v 7.1 was the last release to include build.exe, compiler, linker and libraries.

Now for these platform independent projects that heavily depend on GCC and GNU tool chain I found this mingw32 cross compile environment to be a major blessing. From Linux it produces neat WIN32 binaries with DWARF debugging symbols so that one can use GDB for command line debugging on Windows.


It is fairly easy to setup and build windows 32/64bit binaries right at the comfort of your UNIX environment, and  you can even test them using Wine , at least to see the usage text.

For CentOS one can conveniently install using yum repositories plus all other libraries your project depends on. For example expat, curl, glib-2 etc are available.

 # yum install mingw32-gcc

If the project is using automake configure script, you can configure for mingw32 as follows. Of course if the project uses specialized libraries you have to manually tweak it.

# ./configure --host=i686-w64-mingw32

For cross compilation the gcc will be as follows.

CC = i686-w64-mingw32-gcc ,  for 32bit binaries

CC = x86_64-w64-mingw32-gcc , for 64bit binaries.

The mingw32 compiler environment is rooted at /usr/i686-w64-mingw32/sys-root/mingw and you can see all the bintools as

i686-w64-mingw32-addr2line   i686-w64-mingw32-gcov
i686-w64-mingw32-ar          i686-w64-mingw32-gprof
i686-w64-mingw32-as          i686-w64-mingw32-ld
i686-w64-mingw32-c++         i686-w64-mingw32-ld.bfd
i686-w64-mingw32-c++filt     i686-w64-mingw32-nm
i686-w64-mingw32-cpp         i686-w64-mingw32-objcopy
i686-w64-mingw32-dlltool     i686-w64-mingw32-objdump
i686-w64-mingw32-dllwrap     i686-w64-mingw32-pkg-config
i686-w64-mingw32-elfedit     i686-w64-mingw32-ranlib
i686-w64-mingw32-g++         i686-w64-mingw32-readelf
i686-w64-mingw32-gcc         i686-w64-mingw32-size
i686-w64-mingw32-gcc-4.9.3    i686-w64-mingw32-strings
i686-w64-mingw32-gcc-ar       i686-w64-mingw32-strip
i686-w64-mingw32-gcc-nm       i686-w64-mingw32-windmc
i686-w64-mingw32-gcc-ranlib   i686-w64-mingw32-windres

No development setup is complete without making hello, world. In the next posting I will introduce you to the hello world file system program using Crossmeta  FUSE SDK on Windows, but we will be cross-compiling on Linux.

Please follow and like us: