Hardware Reference
In-Depth Information
This should also produce no errors. Normally the next step would be to run
make install
but that won't be very
helpful. Change into the
src
directory and run the
file
command:
# file hello
Now take a look at Figure
6-15
and you can see why it's not helpful.
Figure 6-15.
Why running make install would be bad
It's now quite clear why
make install
would not go as planned. It's always a good idea to run the
file
tool across
your cross compiled binary files: this will make sure that you have in fact cross compiled the application and not just
used the local version of GCC. Now copy the
hello
application across to your Raspberry Pi by whatever means fits
best. I like to use
scp
to copy the file from my build machine to my Raspberry Pi. You could also insert the SD card
back into your host machine if you wanted to. Now it's time to see if it really worked. Run the
hello
application.
The GNU
hello
application supports a few options; in Figure
6-16
you can see my favorite option and its output.
Figure 6-16.
The output of the GNU hello application
Congratulations! You have your first cross compiled application. Unfortunately, GNU
hello
is not very useful.
I do use it to test my tool chains; after all, I know the source code is in a well-maintained and working state.
Now that you have tested your tool chain, try and compile a small simple application. I will show you another
example for the application called
netcat
. You will be surprised at how easy it is. Listing 6-2 shows the build process.
Listing 6-2.
Commands to Build netcat
# CC=arm-unknown-linux-gnueabi-gcc ./configure --host=arm-unknown-linux-gnueabi
# make
Look familiar? Those are the exact same commands you used to build the
hello
application. It's not hard to cross
compile a program if that program depends on nothing else. What would happen if you wanted to compile a more
complex program when you can't use the system library files (after all, they are compiled for an x86 architecture)?
Cross Compiling with Dependencies
A good example of a program that uses system library files is nmap, which depends on the pcap library files. For you
to be able to build nmap you're going to need to build
libpcap
for the ARM architecture first.
The first step will be to download
libpcap
into your build directory. You can download
libpcap
from
http://www.tcpdump.org/
.
I will be using
libpcap-1.3.0
. Extract the source once the download is finished. I like to
keep the source tarballs as well just in case I make a mess of the compile and install. In Figure
6-17
you can see the
source and its tarballs in my build directory.