2.3 The ARM compiler command

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

Typically, you invoke the compiler as follows:

armcc [options] file_1file_n

You can specify one or more input files. The compiler produces one object file for each source input file.

Building an example image from C++ source

To compile a C++ file called shapes.cpp:

  1. Compile the C++ file shapes.cpp with the following command:
    armcc -c --cpp --debug -O1 shapes.cpp -o shapes.o
    
  2. 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.

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

Command-line options for compiling 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.

Command-line options for compiling Thumb code

The following compiler option generates Thumb code:

--thumb

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

Non-ConfidentialPDF file icon PDF versionARM DUI0529M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.