Compiler and Linker Options
To Contents | To previous page | To next page

## Compiler and Linker Options

eCos is built using the GNU C and C++ compilers. The versions of the tools Red Hat has prepared for this release have some enhancements, such as constructor priority ordering and selective linking, which will eventually become part of the standard distribution.

Some GCC options are required for eCos, and others can be useful. This chapter gives a brief description of the required options as well as some recommended eCos-specific options. All other GCC options (described in the GNUPro manuals) are available.

### Compiling a C Application

The following command lines demonstrate the minimum set of options required to compile and link an eCos program written in C.

### NOTE

Remember that when this manual shows `gcc` you should type the full name of the cross compile,e.g. `mn10300-elf-gcc` , `mips-tx39-elf-gcc` , `powerpc-eabi-gcc` , `sparclite-elf-gcc` , `arm-elf-gcc, mips64vr4300-elf-gcc, or sh-elf-gcc.` When compiling for the synthetic Linux target, use the native gcc which must have the features required by eCos.

    $ gcc -c  -IINSTALL_DIR
    /include file.c
    $ gcc -o program file.o -LINSTALL_DIR
    /lib -Ttarget.ld -nostdlib

### NOTE

- Certain targets may require extra options, for example the SPARClite architectures require the option `-mcpu=sparclite` . Examine the BASE_DIR `/packages/targets` file or BASE_DIR `/examples/Makefile` or the "Global compiler flags" option (CYGBLD_GLOBAL_CFLAGS) in your generated eCos configuration) to see if any extra options are required, and if so, what they are.

The following command lines use some other options which are recommended because they use the selective linking feature:

    $ gcc -c  -I
    INSTALL_DIR
    /include -I. -ffunction-sections -fdata-sections -g -O2 file.c
    $ gcc -o program file.o -ffunction-sections -fdata-sections -Wl,--gc-sections -g -O2 -L
    INSTALL_DIR
    /lib -Ttarget.ld -nostdlib

### Compiling a C++ Application

The following command lines demonstrate the minimum set of options required to compile and link an eCos program written in C++.

### NOTE

- Remember that when this manual shows `g++` you should type the full name of the cross compiler: `mn10300-elf-g++` , `mips-tx39-elf-g++` , `powerpc-eabi-g++` , `sparclite-elf-g++` , `arm-elf-g++, mips64vr4300-elf-g++, or sh-elf-g++.` When compiling for the synthetic Linux target, use the native `g++` which must have the features required by eCos.

    $ g++ -c  -I
    INSTALL_DIR
    /include -fno-rtti -fno-exceptions file.cxx
    $ g++ -o program file.o -L
    INSTALL_DIR
    /lib -Ttarget.ld -nostdlib

### NOTE

- Certain targets may require extra options, for example the SPARClite architectures require the option `-mcpu=sparclite` . Examine the BASE_DIR `/packages/targets` file or BASE_DIR `/examples/Makefile` or the "Global compiler flags" option (CYGBLD_GLOBAL_CFLAGS) in your generated eCos configuration) to see if any extra options are required, and if so, what they are.

The following command lines use some other options which are recommended because they use the selective linking feature:

    $ g++ -c  -IINSTALL_DIR
    /include -I. -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -finit-priority -g -O2 file.cxx
    $ g++ -o program file.o -W1,--gc-sections -g -O2 -LINSTALL_DIR
    /lib -Ttarget.ld -nostdlib

Compiler and Linker Options
To Contents | To previous page | To next page