GCC 4.6.3 for Raspberry Pi cross-compiler Windows-edition

Download samples (sources) Download samples (binary) Buy the build scripts

All software related to build of cross-compiler is licensed under GNU GPLv3.
Full source-code plus full instructions are provided below. You can buy scripts I wrote to simply save your time.
They automatically create both versions (hard-float and soft-float) of the GCC for Windows and apply all required patches.
But this is not required, all needed information you will find while reading.

For Open-Source Projects

If you have an open-source project or want to develop one on Windows and run it to Raspberry Pi, let me know about it. Simply send me a link, short info with purpose and your role in that project and I will provide you the compiler binaries for FREE.


This is a full guide that will let you seamlesly build the GCC cross-compiler for Windows targetting Raspberry Pi running Raspbian OS 3.12. It was based on the unique guide available at GuruCoding.com. Although the original one found to be a bit outdated as future versions of the system were released plus the overall Linux tools progressed in their versions. It relied also on many manual actions, delaying the whole compilation process even more. Beside that it's a really good lecture about building cross-compilers for Windows platform. I personally recommend reading it before moving forward with current guide. Many thanks to Mikhail Kupchik for it.

Issues I solved were like:

Versions

It was tested and targets system (Jan-2015):
  • Raspbian OS - 3.12.35+
  • GCC 4.6.3 (Debian 4.6.3-14+rpi1)
  • eglibc 2.13 (2.13-38+rpi2+deb7u6)
  • binutils 2.24 (2.24.51.20140425)

You can verify your versions following this hint.

Software sources

It is recommended to download following source-code to build everything correctly:

You might also require:

  1. virtual machine with Windows XP and Cygwin installed (mostly with packages for development)
  2. virtual machine with MinGW (with development packages installed)
  3. downloaded software sources and they should be later placed at "/opt/build_src" (zipped as described in Build Steps)
  4. downloaded Mikhail Kupchik's patches-for-raspberry-pi-toolchain.tar.gz (are already included in purchased bundle)

In Jan-2015 it was impossible to build from sources newer version of the Raspberry cross-compiler at all. I spot and found solutions to several severe problems discussed below. It was a really long and boring process, as each time I had to revert my virtual machines and start compilation from the last checkpoint, what sometimes could take hours. Summaryizing at the end, the whole compilation took me more than a week.

Just a general rule - follow strictly the orignal Mikhail Kupchik's tutorial and apply all my patches after sources extraction, but before any compilation steps.
Or if you think it's too hard, complex or boring - buy my scripts that will do it all for you!

Patches

Here is the list of problems. Dedicated patches are applied automatically, when required during the build process.
  1. Apply patch for binutils-2.24, otherwise it won't compile or will produce invalid ELF files in freestanding mode.
    Info and diff are available here and here.
    
    --- a/bfd/bfd-in.h
    +++ b/bfd/bfd-in.h
    @ -287,9 +287,9 @ 
     
     #define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
     
    -#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
    -#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
    -#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
    +#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE))
    +#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)))
    +#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)))
     /* Find the address one past the end of SEC.  */
     #define bfd_get_section_limit(bfd, sec) \
       (((bfd)->direction != write_direction && (sec)->rawsize != 0	\
    --- a/bfd/bfd-in2.h
    +++ b/bfd/bfd-in2.h
    @ -294,9 +294,9 @ 
     
     #define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
     
    -#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
    -#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
    -#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
    +#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE))
    +#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)))
    +#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)))
     /* Find the address one past the end of SEC.  */
     #define bfd_get_section_limit(bfd, sec) \
       (((bfd)->direction != write_direction && (sec)->rawsize != 0	\
    --- a/bfd/elf.c
    +++ b/bfd/elf.c
    @ -848,11 +848,11 @ _bfd_elf_make_section_from_shdr (bfd *abfd,
       newsect->filepos = hdr->sh_offset;
     
       if (! bfd_set_section_vma (abfd, newsect, hdr->sh_addr)
    -      || ! bfd_set_section_size (abfd, newsect, hdr->sh_size)
    -      || ! bfd_set_section_alignment (abfd, newsect,
    -				      bfd_log2 (hdr->sh_addralign)))
    +      || ! bfd_set_section_size (abfd, newsect, hdr->sh_size))
         return FALSE;
     
    +  bfd_set_section_alignment (abfd, newsect, bfd_log2 (hdr->sh_addralign));
    +
       flags = SEC_NO_FLAGS;
       if (hdr->sh_type != SHT_NOBITS)
         flags |= SEC_HAS_CONTENTS;
    
    $ cat ../binutils_2.24--compilation-error-fix.diff | patch -p1
  2. Make sure MAKEINFO=missing is added to configure command of gcc 4.6.3 to avoid dealing with the texinfo >= 5.0 strictness bugs. (who needs docs anyway!)
    Info is available here, however, they mentioned the wrong setting (no comment).
  3. Patch libgcc2.c as it will cause segmentation fault on later compilers (GCC 4.9.2+) by rewriting ira_allocno_object_iter_cond() method.
    Info is available here.
    
    --- a/gcc/ira-int.h
    +++ b/gcc/ira-int.h
    @ -1138,8 +1138,13 @
     ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a,
     			      ira_object_t *o)
     {
    -  *o = ALLOCNO_OBJECT (a, i->n);
    -  return i->n++ < ALLOCNO_NUM_OBJECTS (a);
    +  int n = i->n++;
    +  if (n < ALLOCNO_NUM_OBJECTS (a))
    +    {
    +      *o = ALLOCNO_OBJECT (a, n);
    +      return true;
    +    }
    +  return false;
     }
     
     /* Loop over all objects associated with allocno A.  In each
    
    $ cat ../gcc_4.6.3--segmentation-fault-compiling-ira.diff | patch -p1
  4. Make eglibc compiled using make 4.0 and inform it that Raspberry Pi ARMv11 can handle some injected assembly
    (instead of failing with message "Error: selected processor does not support ARM mode `rfs r1'").
    Info is available here, here, here, here and here.
    
    --- a/configure
    +++ b/configure
    @ -5347,7 +5347,7 @
       ac_prog_version=`$MAKE --version 2>&1 | sed -n 's/^.*GNU Make[^0-9]*\([0-9][0-9.]*\).*$/\1/p'`
       case $ac_prog_version in
         '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
    -    3.79* | 3.[89]*)
    +    3.79* | 3.[89]* | 4.*)
            ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
         *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
    --- a/configure
    +++ b/configure
    @ -5535,6 +5535,9 @
       { $as_echo "$as_me:$LINENO: checking version of $SED" >&5
     $as_echo_n "checking version of $SED... " >&6; }
       ac_prog_version=`$SED --version 2>&1 | sed -n 's/^.*GNU sed version \([0-9]*\.[0-9.]*\).*$/\1/p'`
    +  if test -z "$ac_prog_version"; then
    +    ac_prog_version=`$SED --version 2>&1 | sed -n 's/^.*(GNU sed).* \([0-9][0-9.]*\).*$/\1/p'`
    +  fi
       case $ac_prog_version in
         '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
         3.0[2-9]*|3.[1-9]*|[4-9]*)
    --- a/configure
    +++ b/configure
    @ -5473,7 +5473,10 @
     $as_echo_n "checking version of $MAKEINFO... " >&6; }
       ac_prog_version=`$MAKEINFO --version 2>&1 | sed -n 's/^.*GNU texinfo.* \([0-9][0-9.]*\).*$/\1/p'`
    +  if test -z "$ac_prog_version"; then
    +    ac_prog_version=`$MAKEINFO --version 2>&1 | sed -n 's/^.*(GNU texinfo).* \([0-9][0-9.]*\).*$/\1/p'`
    +  fi
       case $ac_prog_version in
         '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
    -    4.*)
    +    4.* | 5.*)
            ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
         *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
    --- a/configure.in
    +++ b/configure.in
    @ -1063,7 +1063,7 @
       critic_missing="$critic_missing gcc")
     AC_CHECK_PROG_VER(MAKE, gnumake gmake make, --version,
       [GNU Make[^0-9]*\([0-9][0-9.]*\)],
    -  [3.79* | 3.[89]*], critic_missing="$critic_missing make")
    +  [3.79* | 3.[89]* | 4.*], critic_missing="$critic_missing make")
     
     AC_CHECK_PROG_VER(MSGFMT, gnumsgfmt gmsgfmt msgfmt, --version,
       [GNU gettext.* \([0-9]*\.[0-9.]*\)],
    --- a/ports/sysdeps/arm/preconfigure
    +++ b/ports/sysdeps/arm/preconfigure
    @ -2,7 +2,7 @
     arm*)
     	base_machine=arm
     	case $config_os in
    -	linux-gnueabi)
    +	linux-gnueabi*)
     		machine=arm/eabi/$machine
     		if [ "${CFLAGS+set}" != "set" ]; then
     		  CFLAGS="-g -O2"
    
    $ cat ../eglibc--configure-make4.diff | patch -p1
  5. Find and delete folder 'manual' from 'all-subdirs' parameter from eglibc's Makeconfig, othwerise the whole build will fail during headers installation due to mixed makefile rules.
    Another approach could be simply downgrade 'make' to 3.81, which is however discontinued.
    Info is available here.
    
    --- a/Makeconfig
    +++ b/Makeconfig
    @ -968,7 +968,7 @ $(common-objpfx)gnu/option-groups.stmp:					\
     all-subdirs = csu assert ctype locale intl catgets math setjmp signal	    \
     	      stdlib stdio-common libio malloc string wcsmbs time dirent    \
     	      grp pwd posix io termios resource misc socket sysvipc gmon    \
    -	      gnulib iconv iconvdata wctype manual shadow gshadow po argp   \
    +	      gnulib iconv iconvdata wctype shadow gshadow po argp   \
     	      crypt nss localedata timezone rt conform debug		    \
     	      $(add-on-subdirs) $(dlfcn) $(binfmt-subdir)
    
    
  6. Fix the rpc cross-samples as they look for "rpc/types.h" header file inside invalid folders.
    Info is available here.
    
    --- a/sunrpc/rpc_clntout.c
    +++ b/sunrpc/rpc_clntout.c
    @ -31,7 +31,7 @
      */
     #include <stdio.h>
     #include <string.h>
    -#include <rpc/types.h>
    +#include "rpc/types.h"
     #include "rpc_parse.h"
     #include "rpc_util.h"
     #include "proto.h"
    
    $ cat ../eglibc_2.13--rpc-fix.diff | patch -p1

Build steps (using purchased scripts)

== Cygwin ==

  1. copy the build_in_cygwin.zip into the virtual machine with Cygwin installed
  2. extract the content of the zip file into "C:\cygwin\opt"
    (assuming Cygwin was installed into default location)
    and make sure zipped source-code mentioned in Software sources section
    is placed inside the "C:\cygwin\opt\build_src" folder
    (it will be unzipped automatically)
  3. run Cygwin shell
  4. navigate to "/opt" folder (cd /opt)
  5. run the build script (./build_gcc_cross_raspberry_pi_cygwin.cmd)
  6. wait until it completes
    (this might take even several hours!)
  7. gcc-4.6.3-cygwin-all.tar.gz and gcc-4.6.3-eglibc-2.13-cygwin.tar.gz
    should appear next to the script

== MinGW ==

  1. switch to the virtual machine with MinGW installed
  2. copy the build_in_mingw.zip into that machine
  3. extract the content of the zip file into "C:\MinGW\msys\1.0\opt"
    (assuming MinGW was installed into default location)
    and make sure zipped source-code mentioned in Software sources section
    is placed inside the "C:\MinGW\msys\1.0\opt\build_src" folder
    (it will be unzipped automatically)
  4. copy outcomes from step (7) next to the new build script
    (directly into "C:\MinGW\msys\1.0\opt")
    it will be automatically unzipped, when required
  5. run MinGW shell
  6. navigate to "/opt" folder (cd /opt)
  7. run the build script (./build_gcc_cross_raspberry_pi_mingw.sh)
  8. wait until it completes
    (this might take even longer than before!)
  9. gcc-4.6.3-eglibc-2.13-raspberry-pi-win32.tar.gz
    should appear next to the script, what is the zipped package
    containing both: hard-float and soft-float versions of the GCC compiler
  10. move gcc-4.6.3-eglibc-2.13-raspberry-pi-win32.tar.gz into any Windows machine
  11. unzip it
  12. DONE & enjoy!

/Last update: 08-02-2015/