5.7.3 Placing ARM® C++ library code

You can place C++ library code using a scatter file.

To place C++ library code, specify the library path and library name as the module selector. You can use wildcard characters if required.

Procedure

  1. Create the following C++ program, foo.cpp:
    #include <iostream>
    
    using namespace std;
    
    extern "C" int foo ()
    {
      cout << "Hello" << endl;
      return 1;
    }
  2. To place the C++ library code, define the following scatter file, scatter.scat:
    LR 0x8000
    {
        ER1 +0
        {
            *armlib*(+RO)
        }
        ER2 +0
        {
            *libcxx*(+RO)
        }
        ER3 +0
        {
            *(+RO)
    
            ; All .ARM.exidx* sections must be coalesced into a single contiguous
            ; .ARM.exidx section because the unwinder references linker-generated
            ; Base and Limit symbols for this section.
            *(0x70000001)  ; SHT_ARM_EXIDX sections
    
            ; All .init_array sections must be coalesced into a single contiguous
            ; .init_array section because the initialization code references
            ; linker-generated Base and Limit for this section.
            *(.init_array)
        }
        ER4 +0
        {
            *(+RW,+ZI)
        }
    }

    The name *armlib* matches install_directory\lib\armlib, indicating the ARM® C library files that are located in the armlib directory.

    The name *libcxx* matches install_directory\lib\libcxx, indicating the C++ library files that are located in the libcxx directory.

  3. Compile and link the sources:
    armclang --target=arm-arm-none-eabi -march=armv8-a -c foo.cpp
    armclang --target=arm-arm-none-eabi -march=armv8-a -c main.c
    armlink --scatter=scatter.scat --map main.o foo.o -o foo.axf

    The --map option displays the memory map of the image.

Non-ConfidentialPDF file icon PDF versionARM 100748_0607_00_en
Copyright © 2016, 2017 ARM Limited or its affiliates. All rights reserved.