I have a Raspberry Pi 2. What is the best way to get a functional gcc 5 (from the current trunk) on the Raspberry Pi?

Since compiling gcc takes a good two hours on my x86-based computer and probably a lot longer on a Raspberry Pi, it would be great if someone, who already tried this or has more experience with compiling gcc than me, could either:

  • Confirm if it's possible to compile gcc on the Raspberry Pi itself (is there enough memory?), or;
  • Give me a tested set of configuration options to cross-compile gcc 5 for the Raspberry Pi.

What this question is not about

Yes, you can cross-compile software from your x86 box for the Raspberry Pi. No, I'm not interested in answers that explain to me how to build a cross-compiler, except if that instruction is immediately followed by instructions on how to cross-compile a gcc5 that will run on the Raspberry Pi and compile for the Raspberry Pi with that cross-compiler. Answers that do not answer the question will be downvoted.


I do not know if this works, but, I am trying the build instructions I found here: How to Build a GCC Cross-Compiler for the Raspberry Pi.

Edit: It worked to build 4.9.2. I will also try to build 5 with it.

| improve this answer | |
  • I do not want to build a cross compiler. I want to build a gcc5 that runs on the Raspberry Pi. – FUZxxl Mar 25 '16 at 9:11
  • What do you plan to compile it with? I used the cross compiler to build GCC that runs on the Pi. – Vladinatrix Mar 26 '16 at 9:18
  • That's what I'm asking you. Ideally, I would compile it on the Pi itself but this is probably not possible. I have a cross compiler for the Pi, but as I mentioned before, setting up an environment to cross-compile gcc is tricky and I don't know how to do that. What I want is a gcc5 that runs on the Pi. If you can tell me how to get that, your answer is helpful. – FUZxxl Apr 1 '16 at 12:13

Confirm if it's possible to compile gcc on the Raspberry Pi itself (is there enough memory?)

Yes, it's possible to compile on a Raspberry Pi. However

  1. in some cases it might take tremendously longer than you have patience for
  2. it will uselessly burn out precious flash cells and the SD card will prematurely wear out.

Iif GCC5 is not available on any Linux distribution that you want to install it with, then the only viable option is to cross-compile for the Raspberry Pi.

Give me a tested set of configuration options to cross-compile gcc 5 for the Raspberry Pi.

Now talking of my personal experience: whenever I need to cross-compile, I resort to Gentoo Linux, with its versatile crossdev tool-chain. It'll take quite some time for the tool chain to set up but you only have to do this once.

Any time you need to cross-compile a package requires a simple armv7a-hardfloat-linux-gnueabi-emerge -av <package> on the Gentoo cross-compiling host.

Follow Gentoo Embedded Handbook for more detailed information on how to setup your cross-compiler.

You did not tell but if you have a Debian-based distribution on your Pi you will also have to package the compiled product for Debian. You don't need to install a full-fledged Gentoo with a graphical desktop. You can install Gentoo in a chroot and use it to cross-compile whenever you need to. More on that if you want.

| improve this answer | |
  • I have a cross-compiler that runs on my main machine and compiles for the Raspberry Pi. How do I cross-compile a gcc 5 with it so it runs on the Raspberry Pi? Note that burning out flash is a non-issue, the file systems are mounted from NFS to avoid that. Yes, I want to compile software on the Raspberry Pi. That's the whole point. – FUZxxl Apr 24 '16 at 10:40
  • @FUZxxl how can we answer that if 1) you don't explain what your cross-compiling toolchain is and 2) what your target distribution is? Have you also double-checked GCG-5 is really not available for the distribution on your Pi? We don't guess, we need clues. – user29510 Apr 24 '16 at 10:58
  • Back when I made this post, I used a Debian both on the Pi and on my main machine. Right now I have a Debian on the Pi and a FreeBSD on my main machine. The cross-compile toolchain is gcc based. However, if you could just walk me through the steps to cross compile a gcc, that would be super helpful, because that's where I'm stuck. – FUZxxl Apr 24 '16 at 11:02
  • Please indicate in your question, with links if possible, what steps/tutorial/instructions you followed to get your cross-compiling toolchain ready. Every cross-compiling tool chain has its own lot of peculiarities and specifics. Also bear in mind FreeBSD is not LInux. – user29510 Apr 24 '16 at 11:11
  • I installed the toolchain that came with Debian and the one that came with FreeBSD. – FUZxxl Apr 24 '16 at 11:23

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