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:


    Tells the compiler to compile only, and not link.


    Tells the compiler that the source is C++.


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


    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.


    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:


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

This is the default compiler option.


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



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

Show/hideSee also

Copyright © 2011 ARM. All rights reserved.ARM DUI 0592A