title: Cross-compilation for Raspberry Pi in GCC. Where to start?
body: <blockquote>
    <p><strong>TL/DR</strong>: Where can I find more information about building a GCC 4.7.0 cross-compiling toolchain for ARM (gnueabi) platform (intended to run on a Raspberry Pi device)?</p>
  </blockquote>
  
  <p>I have just got a brand new Raspberry Pi and I am very eager to start programming for it. I've managed to install the GCC toolchain (I am using the Arch Linux system image) and compiled some basic programs, all working fine.</p>
  
  <p>I've also tried to compile the Boost libraries because I often use them in my projects and everything seemed to work fine by following the instructions (<code>./bootstrap.sh</code> + <code>./b2</code>) except for the fact that the compilation was painfully slow. I left it on for a few hours but it barely got past the first few source files. After I left it running for the night, I discovered that the build process aborted due to RAM shortage.</p>
  
  <p>So, my guess is that Rasp Pi is simply underpowered for compiling something of such size as Boost. So, cross-compilation comes to my mind. However, even though there is a lot of information about ARM cross compilation available online, I find it confusing. Where does one even start? </p>
  
  <p>I have a recent GCC version (4.7.0) available on my Raspberry Pi, so I would ideally like to cross-compile with the same version. Where can I get the GCC 4.7.0 toolchain for ARM? (I will be compiling on x86 CentOS 6.2)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I deallocated unneeded GPU memory and set up a 4GB swap partition on a USB drive, while build files are on a NFS share. Boost is now compiling much much faster, so it is manageable. I would still like to know how can I set up a GCC 4.7 toolchain for cross compilation on my x86 PC though, since I intend to do a lot of compiling and I would like it to be as fast as possible.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Since GCC 4.7.0 is relatively new, there does not seem to be a pre-built cross-compiler (i386->ARM). I will probably have to build one myself, which seems an non-trivial task (I've tried and failed). Does anyone know of a tutorial to follow for building a GCC cross-compiler, hopefully for one of the recent versions?  </p>
  
  <p>I've tried with <a href="http://joelinoff.com/blog/?p=658" rel="noreferrer">this great shell script</a> (which worked great for building a same-arch compiler) and I've successfully built <code>binutils</code> and GCC's prerequisites, but then GCC build kept failing with many cryptic errors. I am really lost here, so I would greatly appreciate your help.</p>
  
  <p>GCC on Raspberry Pi was configured with</p>
  
  <pre><code>--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib 
  --mandir=/usr/share/man --infodir=/usr/share/info 
  --with-bugurl=https://bugs.archlinux.org/ 
  --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-shared 
  --enable-threads=posix --with-system-zlib --enable-__cxa_atexit 
  --disable-libunwind-exceptions --enable-clocale=gnu 
  --disable-libstdcxx-pch --enable-libstdcxx-time 
  --enable-gnu-unique-object --enable-linker-build-id --with-ppl 
  --enable-cloog-backend=isl --enable-lto --enable-gold 
  --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold 
  --with-linker-hash-style=gnu --disable-multilib --disable-libssp 
  --disable-build-with-cxx --disable-build-poststage1-with-cxx 
  --enable-checking=release --host=arm-unknown-linux-gnueabi 
  --build=arm-unknown-linux-gnueabi 
  </code></pre>
  
  <p><strong>Edit 3:</strong></p>
  
  <p>I managed to build a 4.7 GCC toolchain for ARM (yay!) using <a href="http://github.com/dwelch67/raspberrypi" rel="noreferrer">this shell script</a> as suggested by user dwelch in the comments. I also built <code>newlib</code> and <code>libstdc++</code> using <a href="http://wiki.osdev.org/OS_Specific_Toolchain" rel="noreferrer">this article</a> as a guide. The toolchain works fine, but hen I run the executable on my Raspberry Pi, it fails with <code>Illegal instruction</code>. What could be the cause of that? </p>