Building a Simple Command Line Program

To build and test a simple command line program:

  1. configure required toolchains; select appropriate compilers and copy c libraries

  2. choose a toolchain

  3. use automated build tools OR compile and link manually

  4. test; copy binary over to target device manually and run it OR run it from the host directory via NFS mount OR set up CPU transparency (recommended).

To test the basic toolchain functionality you can take the universal "hello world" program and build it under the SDK. Hello world library requirements are minimal, as it only uses the printf function that is defined in stdio.h and usually provided by the glibc library.

After initial SDK setup, both PC and ARM toolchains need be created and/or configured. See Installing Scratchbox and Configuring Scratchbox sections for more information.

Start up Scratchbox, select either PC or ARM toolchain, make sure "helloworld.c" exists, and issue the typical "gcc -o helloworld helloworld.c" command. Depending on the toolchain this produces either an x86 or ARM binary. Try switching toolchains and recompiling the same source file for another target. Changing toolchains is easy using the "sbox-config" tool, so versions with different compilers and for different platforms can be built quickly.

Testing the ARM binary requires actual target hardware, or a software emulator which is not covered here. Once the network connection between the host PC and target device has been established, you can just copy the compiled binary file over using "scp" or a similar command and run it there. This is sufficient for quick testing. More serious development work involves mounting host development directory on the target over NFS.

Once you have configured CPU transparency properly it provides the quickest way of building and testing command line applications. After building, the resulting binary is invoked on the host PC just like any other executable file. This is detected by Scratchbox and the binary is actually run on the target device, and any resulting output is communicated back to the host.

Building a simple command line program under the SDK requires only a couple of hours, excluding the time required to setup CPU transparency. The processes of compiling for native target (host PC) or cross-compiling (ARM) are identical.