Chapter 6. Using Sourcery G++ from the Command Line

Abstract

This chapter demonstrates the use of Sourcery G++ Lite from the command line. This chapter assumes you have installed Sourcery G++ Lite as described in Chapter 4, Installation and Configuration. If you prefer to use an integrated development environment to build your applications, you may refer to Chapter 5, Using the Sourcery G++ IDE instead.

Table of Contents

Building an Application
Running an Application

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-symbianelf. If you are using a different target system, you must replace commands that begin with arm-none-symbianelf with the name of your target system.

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

Example 6.1. Hello, World (C)

#include <stdio.h>

int
main (void)
{
  printf("Hello World!\n");
  return 0;
}

Compile and link this program using the command:

> arm-none-symbianelf-gcc -o hello hello.c

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

Sourcery G++ Lite may require that you specify a linker script to build the application. If you receive linker errors like “undefined reference to `read'”, then you must select an appropriate linker script for your target system. Default linker scripts are provided in arm-none-symbianelf/lib. You may use a linker script by adding the following -T script to the compiler command line.