
Building GCC as a Cross Compiler for Raspberry Pi - AlexeyBrin
https://solarianprogrammer.com/2018/05/06/building-gcc-cross-compiler-raspberry-pi/
======
bcaa7f3a8bbc
On Gentoo,

    
    
        crossdev -t armv7a-hardfloat-linux-gnueabi
    

crossdev can create Gentoo ebuilds of a complete set of toolchain for any
platforms.

    
    
        crossdev -t x86_64-w64-mingw32
    

would create a GCC cross-compiler for Windows.

* [https://wiki.gentoo.org/wiki/Crossdev](https://wiki.gentoo.org/wiki/Crossdev)

* [https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Creat...](https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Creating_a_cross-compiler)

* [https://wiki.gentoo.org/wiki/Raspberry_Pi#Crossdev](https://wiki.gentoo.org/wiki/Raspberry_Pi#Crossdev)

* [https://wiki.gentoo.org/wiki/Mingw](https://wiki.gentoo.org/wiki/Mingw)

~~~
bdowling
Crossdev (or variants like crossdev-ng) may work, but only if you stick to the
most well-tested build and target combinations. Otherwise, there are
O(ludicrous) configurations, most of which are untested.

~~~
bcaa7f3a8bbc
Definitely, but Windows and Raspberry Pi are both well-tested I believe.

------
plaes
Why bother?

    
    
      apt install gcc-arm-linux-gnueabihf # Debian / Ubuntu
      dnf install gcc-arm-linux-gnu # Fedora

~~~
lisper
Give me a binary and I hack for a day. Teach me to build a binary and I code
for a lifetime.

(Just in case you didn't get the allusion:
[https://quoteinvestigator.com/2015/08/28/fish/](https://quoteinvestigator.com/2015/08/28/fish/))

~~~
amelius
You mean:

Teach me how to build a compiler binary, and I'll be building compiler
binaries for a lifetime.

which is somewhat less inspirational. Even less so when replacing "compiler
binary" by "other people's code".

I think the main problem with your analogy is that in IT, the "fish" are free.

~~~
lisper
No. I mean: Teach me how to build a compiler binary, and I'll be able to build
pretty much whatever binaries I need whenever I need them for a lifetime.
(What's the point of having a compiler at all if you're not going to build
your own binaries?)

> the "fish" are free

That's true. But if you know how to build them you can make new kinds of fish.
That can come in handy if you don't like the free fish.

~~~
bdowling
Spending all day on a fishing boat when all you want is a fish is an apt
analogy to building GNU cross toolchains for embedded targets.

~~~
lisper
Indeed so. And fishing is not for everyone. But some people find value in it.

------
fest
I found the approach taken by yocto quite powerful: it can be used not only to
compile all kernel and all packages for the target system but also build a
matching SDK (cross-compiler with matching libraries).

The learning curve is quite steep though. For Raspberry Pi this is an
excellent getting-started guide: [http://jumpnowtek.com/rpi/Raspberry-Pi-
Systems-with-Yocto.ht...](http://jumpnowtek.com/rpi/Raspberry-Pi-Systems-with-
Yocto.html)

------
blackflame7000
I really wish I had read this a year ago when I was struggling with cross-
compiling Qt for the RaspberryPi and instead natively built it which took 3
days.

~~~
any1
Well, I've actually spent 3 days trying to get Qt5 to cross-compile for a
custom arm platform. It might be easier for something common like the
raspberry pi, but still, you may have dodged a bullet there. ;)

The worst thing about cross-compiling Qt is that I always run into different
issues with new releases, and it's not even always consistent between builds.
I ended up renting a 64 core VPS to build Qt so that I could iterate faster
though build failures, but it's still at least half a day's work to get it to
build properly.

~~~
blackflame7000
I hear ya, especially with respect to upgrades. Like without fail MYSQL Plugin
will always be missing, QtWebsockets won't build automatically, and even now
on ubuntu 18.04 which ships with openssl1.1.0 I discovered all my applications
can no longer use https properly until I downgraded libssl to 1.0.2

Also: I'm assuming the 64 core machine is ARM? Which provider do you use for
that?

~~~
any1
I'm cross-compiling, meaning I'm not compiling on ARM. ;)

It might be helpful though for 64 bit ARM, but my target architecture is 32
bit and because I need webengine I suspect that it will not compile on a 32
bit platform. The problem is that the linker requires more memory than can be
addressed in a 32 bit address space for linking chrome/webengine.

I just used google cloud.

------
voltagex_
There's also crosstool-ng and buildroot for this, as well as pre built
compilers by Linaro and Bootlin (formerly Free-Electrons). Sorry for lack of
links, extremely limited connection right now.

~~~
vcdimension
[https://crosstool-ng.github.io/](https://crosstool-ng.github.io/)

~~~
voltagex_
Linaro: [https://www.linaro.org/downloads/](https://www.linaro.org/downloads/)

Bootlin: [https://toolchains.bootlin.com/](https://toolchains.bootlin.com/)

------
qalmakka
Damn GCC, that you have to build for each single architecture and os combo.
Clang, being intrinsically a cross-compiler, is much better and way less of a
hassle.

~~~
ndesaulniers
Agreed.

I'm actively trying to replace GCC+binutils for llvm based tools in Android
(and further, at Google). Currently working through some issues for the
kernel, more so llvm's assembler and linker than Clang.

------
anonymous2k
Building a cross compiling toolchain is a good exercise, but if you need to
have a suite of tools/libs, check out llnl's spack. Spack automates building
compilers/toolchains/libs from source, has hundreds of package definitions,
and supports cross compiling. Kinda like Gentoo, but usable on any Linux/Mac
platform.

[http://spack.readthedocs.io/en/latest/basic_usage.html](http://spack.readthedocs.io/en/latest/basic_usage.html)

------
stuaxo
Wish I had this when I was building gstreamer for the raspberry pi, it took
ages!

I tried various solutions like Qemu, but the performance was about the same as
a real Pi.

~~~
voltagex_
Not all software supports being cross compiled - I can't remember if the
problems I had with gstreamer were due to it not being able to be cross
compiled or because I was trying to build Raspbian-compatible .deb files.

------
znpy
I've built a gcc-based cross toolchain for m68k (m68k-linux-gnu iirc) and it
was very easy with crosstool-ng (ct-ng).

I would recommend building a cross-toolchain by hand just a couple of time to
understand the whole process, but then just use ct-ng or something similar: it
gets the job done and it's very configurable (abi, target architecture,
libraries etc).

------
ldng
[http://www.linuxfromscratch.org/](http://www.linuxfromscratch.org/)

------
megous
There's also arch linux arm way, where you control the build/linking from the
target device, but the compilation of object code is done by a cross-compiler
over the network.

------
ythn
Linaro has really good premade cross compilers for ARM

