Chapter 9. Building and Running Sample Applications

The example programs in this tutorial are included, along with a Makefile, in the examples directory of the eCos distribution. The first program you will run is a hello world-style application, then you will run a more complex application that demonstrates the creation of threads and the use of cyg_thread_delay(), and finally you will run one that uses clocks and alarm handlers.

The Makefile depends on an externally defined variable to find the eCos library and header files. This variable is INSTALL_DIR and must be set to the pathname of the install directory created in the Section called Configuration Tool on Windows and Linux Quick Start in Chapter 7.

INSTALL_DIR may be either be set in the shell environment or may be supplied on the command line. It is set by within shells opened by the eCos Configuration Tool using Tools->Shell. To set it in another shell do the following in a bash shell where <BASE_DIR> is the base directory containing the _install directory (e.g. $HOME/ecos-work):

$ export INSTALL_DIR=<BASE_DIR>/arm_install

You can then run make without any extra parameters to build the examples.

Alternatively, if you can do the following:

$ make INSTALL_DIR=<BASE_DIR>/arm_install

eCos Hello World

The following code is found in the file hello.c in the examples directory:

eCos hello world program listing

/* this is a simple hello world program */
#include <stdio.h>
int main(void)
 printf("Hello, eCos world!\n");
 return 0;

To compile this or any other program that is not part of the eCos distribution, you can follow the procedures described below. Type this explicit compilation command (assuming your current working directory is also where you built the eCos kernel):

$ TARGET-gcc -g -I<BASE_DIR>/install/include hello.c -L<BASE_DIR>/install/lib -Ttarget.ld -nostdlib

The compilation command above contains some standard GCC options (for example, -g enables debugging), as well as some mention of paths (-I<BASE_DIR>/install/include allows files like cyg/kernel/kapi.h to be found, and -L<BASE_DIR>/install/lib allowsthe linker to find -Ttarget.ld).

The executable program will be called a.out.

Note: Some target systems require special options to be passed to gcc to compile correctly for that system. Please examine the Makefile in the examples directory to see if this applies to your target.

You can now run the resulting program using GDB in exactly the same the way you ran the test case before. The procedure will be the same, but this time run TARGET-gdb specifying -nw a.out on the command line:

$ TARGET-gdb -nw a.out

For targets other than the synthetic linux target, you should now run the usual GDB commands described earlier. Once this is done, typing the command "continue" at the (gdb) prompt ("run" for simulators) will allow the program to execute and print the string "Hello, eCos world!" on your screen.

On the synthetic linux target, you may use the "run" command immediately - you do not need to connect to the target, nor use the "load" command.

Documentation license for this page: Open Publication License