You copied the Doc URL to your clipboard.

Building an image from C source

This example shows how to build an image from C code with armclang and armlink.

To compile a C source file hello_world.c:

Procedure

  1. Compile the C source with the following command:
    armclang --target=arm-arm-none-eabi -march=armv8-a -c -O1 -o hello_world.o -xc -std=c90 -g hello_world.c

    The following options are commonly used:

    --target=arm-arm-none-eabi
    Targets the AArch32 architecture profile.
    -march=armv8-a

    Targets the ARMv8-A architecture profile.

    Note

    For AArch32 targets (--target=arm-arm-none-eabi) there is no default architecture profile, so you must specify either -march (to target an architecture) or -mcpu (to target a processor). However for AArch64 targets (--target=aarch64-arm-none-eabi), ARMv8-A is the default architecture profile, and the -march option is not required.
    -c

    Tells the compiler to compile only, and not link.

    -xc

    Tells the compiler that the source is C code.

    Note

    The compiler infers the source code language from the filename extension. The -x option overrides the inferred language setting. The -x option is not required for this example, it is provided for illustrative purposes only.
    -std=c90

    Tells the compiler that the source is ISO C90 C code.

    -O1

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

    -g

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

    -o filename

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

  2. Link the file:
    armlink hello_world.o --info totals -o hello_world.axf
  3. Use an ELF and DWARF 4 compatible debugger to load and run the image.
Was this page helpful? Yes No