Thursday, March 6, 2014

How to build a cross compiler for Raspberry Pi using crosstool-ng

Normally I'm working with a Mac and OpenCV. But I want to run OpenCV on a Raspberry Pi for a small preject. Since I don't want to compile on the Raspberry and lose a lot of time, I was looking for a cross compiler. Looks like this is easier from a Linux machine. I had an old Windows laptop left and so I installed Ubuntu 12.04 LTS along with Windows 7 on it.

I found some really good tutorials about this so I won't repeat them and just give you some links:

1. Very clear tutorial. Lightweight for a good overview:
http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/
2. More detailed with screenshots:
http://www.kitware.com/blog/home/post/426

I really like the first tutorial but it's missing information about packages you have to install before you can build crosstool-ng. On Ubuntu you do this with this command in the terminal:
 sudo apt-get install PACKAGE_NAME  
The second link already names some packages, but not all of them. I got errors when I tried to build the toolchain, for example subversion is needed to download a package during the build process. So here is a list of what I installed (replace PACKAGE_NAME with the name below to install):
  • libssl-dev 
  • openssh-server 
  • git-core 
  • pkg-config 
  • build-essential 
  • curl
  • gcc 
  • g++
  • bison 
  • flex 
  • gperf 
  • libtool 
  • texinfo 
  • gawk 
  • automake 
  • libncurses5-dev
  • subversion
Lot's of stuff, but finally I got the toolchain built.

The tutorial says that we have to add the compiler to our $PATH. This is done with this command (don't forget editing the path to your compiler):
 export PATH=$PATH:/PATH/TO/x-tools/arm-unknown-linux-gnueabi/bin  
Remember that this is only temporal! The next time you open your terminal you have to add this to your $PATH again

After this we can compile a "Hello World!" program with this command (source code):
 arm-unknown-linux-gnueabi-c++ hello.cpp -o hello  

Program versions:
OS: Ubuntu 12.04 LTS
crosstool-ng 1.19.0
gcc-linaro 4.8-2013.06-1

No comments:

Post a Comment