Cross compiling is something I’ve never really had a need to do before. All of my past Linux machines have been your standard 32Bit or 64Bit x86 based PCs, and have been fast enough that I’ve been able to compile on the machine it’ll be running on.
But, if a 15 hour XBMC compile taught me anything (other than the fact that XBMC doesn’t work fantastically on the CubieBoard), it’s that I need to setup a decent Linux box, and learn to cross compile for ARM based hardware.
I’ve also always wanted to create my own Linux setup from scratch for a long time. The CubieBoard gives me the opportunity to do this, but it will require some cross compiling to get things started.
I’m starting this post while I’m still in the “I really need to figure this out” stage, but by the time I’ve finished this post, I should hopefully have a Linux box fully up and running, probably with Debian, and a way to compile code destined for ARM. We’ll see.
Note : I actually decided to go with Debian Wheezy running through VirtualBox on my Windows 7 machine. At least for now.
But the rest of what follows will be a few links to things that have helped me get everything up and running and (hopefully) working.
My first goal is to compile a small application on x86 Debian that will run on a CubieBoard. What the application is doesn’t really matter, I’ll just whip some quick code as a simple basic test to see if it actually works.
As I’m running Debian through VirtualBox with a 64GB partition, it’s easy to make backups from which I can easily restore the system when I inevitably screw it up.
As I said, this is something I’ve never tried before, have no idea what software I need to install to make it work, so yes, it’s inevitable.
After doing a bit of Googling, this looks like it could be a good starting point.
Well, the first part, “Preparing for the Build”, seems to have gone ok with GCC, make, bison, Flex, GMP, MPFR and MPC all installing fine through apt-get.
The GCC installation that comes with Debian Wheezy is 4.7.2, so I shall be downloading the same version of the source to compile as my cross compiler.
And also binutils 2.22.
So, preparation time…
- export PREFIX=”$HOME/opt/cross”
- export TARGET=arm-none-eabi
- export PATH=”$PREFIX/bin:$PATH”
So things will be put into /root/opt/cross (yes, I’m doing it as root – it’s VirtualBox, only I will ever have access to it anyway).
Ok, binutils compiled, seemed to install in the right directory without a hiccup. Now for GCC.
The linked cross compiling “tutorial” above notes…
- # If you wish to build these packages as part of gcc:
- mv libiconv-x.y.z gcc-x.y.z/libiconv # Mac OS X users
- mv gmp-x.y.z gcc-x.y.z/gmp
- mv mpfr-x.y.z gcc-x.y.z/mpfr
- mv mpc-x.y.z gcc-x.y.z/mpc
So, I also downloaded the source for gmp, mpfr and mpc, too.
“make all-gcc” and “make all-target-libgcc” went off without a hitch, as did installing them both into /root/opt/cross.
The below line has been added to ~/.bashrc
- export PATH=”$HOME/opt/cross/bin:$PATH”
There’s no header files in there (looks like I’ll have to compile a kernel first), which means I can’t even compile helloworld.c as a test, but I’ve got the basics installed, and seemingly working, so that’ll do for tonight.
It’s late, and I have a feeling I’m doing all this completely wrong, but only time will tell.
Posting a link here just so I have it as a handy reference when I come back to this subject again.