Chapter 4. Using Sourcery CodeBench from the Command Line

This chapter demonstrates the use of Sourcery CodeBench Lite from the command line.

Table of Contents

4.1. Building an Application
4.2. Running Applications on the Target System
4.3. Running Applications in the Simulator
4.4. Running Applications from GDB

4.1. Building an Application

This chapter explains how to build an application with Sourcery CodeBench Lite using the command line. As elsewhere in this manual, this section assumes that your target system is arm-none-eabi, as indicated by the arm-none-eabi command prefix.

Using an editor (such as notepad on Microsoft Windows or vi on UNIX-like systems), create a file named main.c containing the following simple factorial program:

#include <stdio.h>

int factorial(int n) {
  if (n == 0)
    return 1;
  return n * factorial (n - 1);
}

int main () {
  int i;
  int n;
  for (i = 0; i < 10; ++i) {
    n = factorial (i);
    printf ("factorial(%d) = %d\n", i, n);
  }
  return 0;
}

Compile and link this program using the command:

> arm-none-eabi-gcc -o factorial main.c -T script

Sourcery CodeBench requires that you specify a linker script with the -T option to build applications for bare-board targets. Linker errors like undefined reference to `read' are a symptom of failing to use an appropriate linker script. Default linker scripts are provided in arm-none-eabi/lib. Refer to Chapter 5, “CS3™: The CodeSourcery Common Startup Code Sequence” for information about the boards and linker scripts supported by Sourcery CodeBench Lite. You must also add the processor options for your board, as documented in that chapter, to your compile and link command lines.

There should be no output from the compiler. (If you are building a C++ application, instead of a C application, replace arm-none-eabi-gcc with arm-none-eabi-g++.)