Hardware Reference
In-Depth Information
Chapter 6
Cross-Compiling
Embedded computers often lack the necessary resources for developing and compiling
software. The Raspberry Pi is rather special in this regard since it already includes the
gcc compiler and the needed linking tools (under Raspbian Linux). But while the code
can be developed and built on the Raspberry Pi, it may not always be the most suitable
place for software development. One reason is the lower performance of the SD card.
To compile native code for the Raspberry Pi, you need a compiler and linker that
knows how to generate ARM binary executables. Yet it must run on a host with a different
architecture (for example, Mac OS X). Hence the reason it is called a cross -compiler. The
cross-compiler will take your source code on the local (build) platform and generate ARM
binary executables, to be installed on your target Pi.
There are prebuilt cross-compile tools available, including the Raspberry Pi
Foundation's own tools ( git://github.com/raspberrypi/tools.git ), but these can
be problematic for some versions of Linux. Running the cross-compiler on a different
Linux release than it was built for may cause the software to complain about missing or
incompatible shared libraries. But if you find that you can use a prebuilt release, it will
save considerable time.
In this chapter, you'll walk through how to build your own cross-compiler. This may
permit you to get the job done using your existing Linux release.
Terminology
Let's first cover some terminology used in this chapter:
build : Also called the local platform, this is the platform that
you perform the compiling on (for example, Mac OS X).
target : The destination platform, which is the Raspberry Pi
(ARM) in this chapter.
Let's now consider some of the cross-compiling issues before you take the plunge.
There are two main problem areas in cross-compiling:
All C/C++ include files and libraries for the Raspberry Pi (ARM)
must be available on your build platform.
The cross-compiler and related tools must generate code suitable
for the target platform.
 
Search WWH ::




Custom Search