Using the compiler

The compiler, armcc, can compile C and C++ source code into ARM and Thumb code.

Typically, you invoke the compiler as follows:

armcc [options] ifile_1 ... ifile_n

You can specify one or more input files.

Show/hideCompiling example

To compile the C++ example source file shapes.cpp:

  1. Compile the C++ file shapes.cpp with the following command:

    armcc --cpp --debug -c -O1 shapes.cpp -o shapes.o
    

    The following options are commonly used:

    -c

    Tells the compiler to compile only, and not link.

    -cpp

    Tells the compiler that the source is C++.

    --debug

    Tells the compiler to add debug tables for source-level debugging.

    -O1

    Tells the compiler to generate code with restricted optimizations applied to give a satisfactory debug view with good code density and performance.

    -o filename

    Tells the compiler to create an object file with the specified filename.

    Note

    Be aware that --arm is the default compiler option.

  2. Link the file:

    armlink shapes.o --info totals -o shapes.axf
    
  3. Use an ELF, DWARF 2, and DWARF 3 compatible debugger to load and run the image.

See the readme.txt file that accompanies the example for more information.

Show/hideCompiling for ARM code

The following compiler options generate ARM code:

--arm

Tells the compiler to generate ARM code in preference to Thumb code. However, #pragma thumb overrides this option.

This is the default compiler option.

--arm_only

Forces the compiler to generate only ARM code. The compiler behaves as if Thumb is absent from the target architecture. Any #pragma thumb declarations are ignored.

Show/hideCompiling for Thumb code

To build a Thumb version use:

armcc --thumb ...

where:

--thumb

Tells the compiler to generate Thumb code in preference to ARM code. However, #pragma arm overrides this option.

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0529C
Non-ConfidentialID080411