Chapter 4. Using Sourcery G++ from the Command Line
Prev |  | Next

## Chapter 4. Using Sourcery G++ from the Command Line

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

## 4.1. Building an Application

This chapter explains how to build an application with Sourcery G++ Lite using the command line. As elsewhere in this manual, this section assumes that your target system is arm-none-linux-gnueabi, as indicated by the `arm-none-linux-gnueabi` 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-linux-gnueabi-gcc -o factorial main.c

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

Prev |  | Next
3.12. Object File Portability | Home | 4.2. Running Applications on the Target System