Tag Archives: cross compiler

Linux hosted mingw w64 C,C++ and Java cross compiler

Hi everyone !

As i said in my previous article, i want to share with you about the steps to get a fully working w64-mingw32 gcc and gcj 4.6.0 toolchain. I’ll try to be as accurate as possible. Despite of all my efforts, I didn’t manage to get the multilib compiler to build, so I will only describe the steps to get an i686 compiler. Most of the content of this post is based upon mingw w64 instructions, but as I didn’t manage to get it fully compiling following theses instructions, that’s why I’m writing this post.

The times given in this article are thoses obtained with an Intel Xeon CPU X5560 @ 2.80GHz.
The gcc version used was:
gcc version 4.1.2 20080704 (Red Hat 4.1.2-48).


  • Native working gcc/gcj installed (at least 4.1), for i686 architecture
  • Environment variables:
    • $work = directory where to work (for example, $HOME/mingw)
    • $prefix = directory where to install the cross compiler (for example, $work/root)
    • $CFLAGS = optimization flags (for example “-march=core2 -mtune=core2 -O2 -pipe”, see Safe CFLAGS for how to define them),
  • Directories:
    • mkdir -p $work/sources $work/tarballs $work/builds $prefix


Retrieve the following sources in the directory $work/tarballs:

  1. binutils 2.21.51
  2. gcc 4.6.1 20110401: core, g++, java, fix for libjava build error, fix for boehm-gc dll exports, fix for gcj spec file
  3. mingw-w64-trunk-r4105-20110404
  4. ecj 4.5
  5. ppl 11.2, cloog 0.16.2
  6. mpfr 3.0.1, gmp 5.0.1, mpc 0.9

Once everything is retrieved, check that files you downloaded are valid using provided sha1sums.txt (download it to $work/tarballs) and the following command:

# cd $work/tarballs
# sha1sum -c sha1sums.txt
binutils-2.21.51.tar.bz2: OK
cloog-0.16.2.tar.gz: OK
ecj-4.5.jar: OK
gcc-4.6.1-20110401-fix-boehm-gc-dll-export.patch: OK
gcc-4.6.1-20110401-fix-gcj-spec-file.patch: OK
gcc-4.6.1-20110401-fix-libjava-reflect-build-error.patch: OK
gcc-core-4.6-20110401.tar.bz2: OK
gcc-g++-4.6-20110401.tar.bz2: OK
gcc-java-4.6-20110401.tar.bz2: OK
gmp-5.0.1.tar.bz2: OK
mingw-w64-trunk-r4105-20110404.tbz2: OK
mpc-0.9.tar.gz: OK
mpfr-3.0.1.tar.bz2: OK
ppl-0.11.2.tar.bz2: OK

Read more »

Dealing with MinGw cross compiler

Since i’m working on an open-source project to provide easy-to-use asynchronous network I/O framework, and with the aim to make this project as portable as possible, i had to deal with building a cross-compiler for Windows platform, and i’m sorry to say that it wasn’t an «out-of-the-box» task.

When i first started this, i tried to use Mingw, but their website was just hacked the same time i needed it, so back on google, where i found w64 cross compiler project. The documentation was quite easy to follow, and it took me around 1 day to get it working.

I followed theses instructions with an half success. Actually, they are saying that we can build a multilib compiler, but i found out that only the 32 bits compiler was able to build. For the multilib, it fails to build because of incompatible registers name in the early stage 1 of gcc. Also, i wanted to use JNI interface without the need to uses a JDK (mostly because JNI headers are not located in standard locations, for instance with Gentoo, it was under /opt), so i needed to build the GCJ compiler, which is mostly a pain in the ass ! First of all, it seems the cross-compiling is very difficult to reach, mostly because it seems there is no maintainers for the Makefiles, for example, compiling ecjx.exe fails with original sources, as it is trying to build it with the cross compiler, instead of the host’s one. Fixing it was not easy, but i manage to get it to work.

Well, after some time tweaking the Makefiles by myself, i finally got my w64-mingw32 gcc 4.6.0 compiler, and it’s working like a charm. I managed to use most of win32 API without any problem, except that for Condition Variables, i had to take the mingw trunk crt.

So if some of you needs help to develop portable applications for both Win32 and Linux, i am now able to point you things out 😉

In a future article, i will try to describe the steps to have a fully working i686-w64-mingw32-{gcc,ecj} toolchain, so see you soon !