Chapter 5. 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.

Table of Contents

Building an Application
Running Applications on the Target System
Running Applications from GDB

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 mips-sde-elf, as indicated by the mips-sde-elf command prefix.

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 5.1. Hello, World (C)

#include <stdio.h>

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

Compile and link this program using the command:

> mips-sde-elf-gcc -o hello hello.c -T script

Sourcery G++ 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 mips-sde-elf/lib.

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