Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I already asked this question on Stack Overflow, but I would like to know if anyone managed to build a GCC 4.7 toolchain for ARM cross-compilation (for a x86/x86-64 Linux host). There are many instructins for building GCC from source and many available cross-compilers for pre-4.7 GCC versions, just not the latest one.

Compiling on Rasp Pi itself works fine but is just a bit too slow for practical purposes.

I am eager to get compiling and I would like to use the latest and the best tools.

share|improve this question
    
This seems along the lines what I need to do as well. We are developing for an ARM5 running Arch Linux. Development is on Ubuntu Linux 10.04 LTS (today, maybe we upgrade that tomorrow, I don't know yet). Currently we are running GCC 4.4, but the things I need to do will be helpful if not require GCC 4.7 (minimum) if not GCC 4.8 (if we can manage it), for C++11 language features. It seems like all the tool chains available for ARM (5 or anything else) are helplessly out-dated. Is it possible to build a cross compiler tool chain from source and support the GCC we want? –  mwpowellhtx Mar 1 '13 at 22:38
    
I have a little problem in the second step. in fact, I've done the ./configure and make commands. Everything works fine. but when i've tiped "install", i got an error message saying: install: missing file operand –  user8773 Jul 31 '13 at 7:57
add comment

5 Answers

up vote 33 down vote accepted

I found these instructions How to build a cross compiler for your Raspberry Pi. It is a great walk through using a crosstool-ng tool which simplifies configuring a cross-compiler build A LOT (it has a nice curses-based interface) and it supports GCC 4.7.

I've followed these steps and ended up with a successful build of a 4.7 cross-compiler.

Prerequisites: The following packages are required:bison, flex, gperf, gawk, libtool, automake, g++, ensure these are installed before proceeding.

  1. First download crosstool-ng from here (I used version 1.15.2).
  2. Unpack the distribution and do a ./configure / make / install
  3. Create a fresh directory somewhere in the file-system to build in and cd into it.
  4. Run ct-ng menuconfig. You will be presented with a nice set of menus to configure your build.
  5. Go into Paths and misc options. Enable Try features marked as EXPERIMENTAL.
  6. Choose a suitable Prefix directory. This is the directory that your compiler and libraries will get installed in (anything is fine basicallly, just make sure that the directory is empty).

    • NOTE: It is also important that you have write access to the chosen folder
  7. Go to the Target options menu.

    • Target architecture: arm
    • Endianness: little endian
    • Bitness: 32-bit
  8. You may also want to set floating point parameter to softfp (see this for more info), but hardfp is more appropriate for Raspbian.

  9. Go to Operating system menu and change Target OS to linux.
  10. Go to C compiler menu and choose gcc version 4.7.0 (the article recommends Linaro, but I managed to get it working with vanilla gcc). Also chose additional languages you want to be able to compile (C++, Fortran, ...)
  11. Go to C-library menu and chose one. The default is eglibc but that one didn't build fine for me, so I used glibc (the newest version).

    • NOTE: during the build step 13. eglibc can fail to build if subversion is not installed, as the source can't be retrieved from the repository
  12. Exit the configuration tool while saving your changes.
  13. Run ct-ng build in the same directory. Wait a while (about 45 minutes in my case) and your cross compiler should be ready.

Seems to work great!

share|improve this answer
    
Wow, 45 minutes is a long time. How quick is your system? I'm waiting now. –  Jivings Jun 14 '12 at 15:46
    
Well, maybe it was a bit less, but it has to compile all the prerequisites first and after bintools and gcc also libc and libstdc++, so 45 min sounds reasonable to me. –  Tibor Jun 14 '12 at 15:55
    
Could we add details on how to install these properly and update the path, once tested of course? –  Alex Chamberlain Jun 27 '12 at 16:38
1  
Also, I think we should be using hardfp, as the RPi supports it. –  Alex Chamberlain Jun 27 '12 at 16:39
    
May be, but IIRC, the Arch's GCC is configured with softfp. I don't have time to test this now, but I've made the answer community wiki, so feel free to improve it. –  Tibor Jun 28 '12 at 11:10
show 3 more comments

I am eager to get compiling and I would like to use the latest and the best tools.

In fact, the latest and best tools do not need to be built by yourself. On the Raspberry Pi Tool GitHub Repository you will find the X86_64 and x686 toolchains for cross-compiling software.

I recommend using the x86-linux64-cross-arm-linux-hardfp toolchain, as that will compile for Hard Floating Point, which will result in a much faster system.

$ arm-bcm2708hardfp-linux-gnueabi-gcc --version

arm-bcm2708-linux-gnueabi-gcc-4.5.1 (Broadcom-2708) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.

Note: If you are using an existing kernel then you will have to use the toolchain that matches the kernel. HardFP applications will not work on a SoftFP kernel.


To use the toolchain simply check out the repository:

git clone https://github.com/raspberrypi/tools.git --depth 1

The --depth parameter will mean that you don't have to wait for the repository history to be downloaded as well (since we wont be using it).

Then add the binaries to your PATH variable:

export PATH=~/tools/arm-bcm2708/x86-linux64-cross-arm-linux-hardfp/bin:$PATH

Or to persist the PATH:

echo "export PATH=~/tools/arm-bcm2708/x86-linux64-cross-arm-linux-hardfp/bin:$PATH" >> ~/.bashrc
source ~/.bashrc

To compile with the tool chain you can now add the CROSS_COMPILE parameter. For example, when running make:

make CROSS_COMPILE=arm-bcm2708hardfp-linux-gnueabi- 

Or to make this easier, you can save the variable to bashrc again:

echo "export TARGET=arm-bcm2708hardfp-linux-gnueabi" >> ~/.bashrc
source ~/.bashrc

and now use the variable when compiling:

make CROSS_COMPILE=${TARGET}
share|improve this answer
1  
This seems to be gcc-4.5.1. –  Tibor Jul 18 '12 at 10:57
    
@Tibor Is that bad? –  Jivings Jul 18 '12 at 11:04
    
@Jivings It totally does not answer the question! –  Alex Chamberlain Jul 18 '12 at 11:26
1  
I disapprove of the downvotes. @AlexChamberlain It suggests a valuable alternate method to the time consuming act of building your own toolchain. –  Jivings Jul 18 '12 at 15:11
1  
@Jivings: This is very helpful. Meanwhile it is gcc4.7.1 (the best I ever had) and floating point works right away. I couldn't make floating point work using Chris' original description that Tibor posted. Thanx a lot. –  user3802 Dec 15 '12 at 9:05
show 4 more comments

Note that when building the toolchain using ct-ng on centos 6.3 on a 64 bit system I was forced to deselect the option to statically link libstdc++ because static linking was not supported on the platform (apparently).

Also, while it would be great to use the prebuilt toolchain from the git repository, that chain does not seem to work on Centos 6.3 - probably because it is built for a more modern system or something. I did not really try to run this down.

share|improve this answer
add comment

If you want to benefit from a fast host for compiling things for your RPI I suggest to work in cross environment via chroot and QEMU. This by the way supersedes a cross compiler with no hassle.

Simply setup a Debian cross-environment using debootstrap/multistrap

http://wiki.debian.org/EmDebian/CrossDebootstrap#QEMU.2BAC8-debootstrap_approach

(see chapter QEMU/debootstrap approach) and you are done.

share|improve this answer
add comment

If you installed Ubuntu 64 bits edition and the tools from Raspberry Pi SVN and you are getting the error:

-bash: /home/I/toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-c++: 
No such file or directory

just run:

sudo apt-get install ia32-libs
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.