All right, we want to develop appplications for Linux and Windows. For that we need some Tools for actually building software for i686 and x86_64 machines. Linux is a much better development environment I want to build the applications on linux. For that I need the Windows Incudes and libraries (mingw32) and the compilation tools (gcc-5.1.0) and binutils (binutils-2.25). This howto is just a short showcase on how to create toolchains for your service, for a complete list of configuration go to

export PREFIX=/home/$USER/your/path_for_build

export PATH=/home/$USER/your/path_for_build/bin:$PATH

e.g. : export PATH=$PREFIX/bin:$PATH

export TARGET=i686-pc-mingw32 or export TARGET=x86_64-pc-mingw32

HOST = x86_64-unknown-linux-gnu.

    1. Required packages
      1. mingw-w64-v4.0.2.tar.bz2
      2. binutils-2.25.tar.gz
      3. gcc-5.1.0.tar.bz2
    2. Building mingw32 Headers for i686-pc-mingw and x86_64-w64-mingw32
      1. cd cd /home/$USER/src
      2. tar -xf mingw-w64-v4.0.2.tar.bz2
      3. cd mingw-w64-v4.0.2/mingw-w64-headers
      4. ./configure --host=$TARGET --prefix=$PREFIX/$TARGET
        1. IMPORTANT: The Headers must be configured with the used Target in the prefix for the right configuration
        2. For Reference:
      5. make & make install
    3. Building Binutils
      1. cd /home/$USER/src
      2. tar -xf binutils-2.25.tar.gz
      3. mkdir /home/$USER/src/build_binutils
      4. cd build_binutils
      5. ../binutils-2.25/configure --prefix=$PREFIX --target=$TARGET --with-sysroot=$PREFIX
      6. make (-j4)
      7. make install
      8. cd $PREFIX
      9. ln -s ../lib ./$TARGET/lib
      10. ln -s ../include ./$TARGET/include
    4. First Building gcc-5.1.0 all-gcc before building gcc for w32API building
      1. cd /home/$USER/src
      2. tar -xf gcc-5.1.0.tar.bz2
      3. mkdir build_gcc
      4. cd build_gcc
      5. ../gcc-5.1.0/configure --prefix=$PREFIX --target=$TARGET --enable-languages=c,c++ --libexecdir=$PREFIX/lib --disable-static --enable-threads=win32 --with-sysroot=$PREFIX
      6. make all-gcc (-j4)
      7. make install-gcc
    5. Build Mingw32 CRT Runtime
      1. Buidling the Runtime Libs for the choosen Target
      2. ./configure --prefix=$PREFIX --host=$TARGET --with-sysroot=$PREFIX --libdir=$PREFIX/lib --oldincludedir=$PREFIX/include
      3. There is a possibility that a dependency is not found. I could not figure out how to solve it. So I defined them in the neccessary file. But only if you have to.
        1. #ifndef _MCW_DN
          #define _MCW_DN 0x03000000

          #define _MCW_EM         0x0008001F      /* Error masks */
          #define _MCW_IC         0x00040000      /* Infinity */
          #define _MCW_RC         0x00000300      /* Rounding */
          #define _MCW_PC         0x00030000      /* Precision */

      4. make (-j4)
      5. make install
    6. Second full gcc build.
      1. cd /home/$USER/src/build_gcc
      2. rm -rf *
      3. ../gcc-5.1.0/configure --prefix=$PREFIX --target=$TARGET --enable-languages=c,c++ --libexecdir=$PREFIX/lib --disable-static --enable-threads=win32 --with-sysroot=$PREFIX
      4. OR
      5. ../gcc-5.1.0/configure --prefix=$PREFIX --target=$TARGET --enable-languages=c,c++ --libexecdir=$PREFIX/lib --enable-static --enable-threads=win32 --with-sysroot=$PREFIX
      6. make (-j4)
      7. make install
    7. Now it is time to test the toolchain
      1. cd $PREFIX
      2. Create a test.c file withe the content:
        int main() 
            printf("Hello World!\n"); return 0; 
      3. ./bin/$TARGET-gcc test.c -o test.exe
    8. Run the test
      1. wine ./test.exe --silent
      2. vi test.c
      3. include the text below
      4. #include 
        int main() {
                printf("Hello World!\n");
                return 0;
      5. wine testexe



Now the test in Windows itself. Windows XP in this case

winxp testexe



Note: I am not responsible for any consequences you may experience following the technical descriptions on, regardless of what, who, why and how. I am not responsible, no way.