4.8 C and C++ language interworking

When compiling C or C++ modules for interworking, you must specify the --apcs=/interwork compiler option.

C and C++ language interworking

This example shows a main() function implemented in Thumb that carries out an interworking call to an ARM subroutine. The ARM subroutine makes an interworking call to printf() in the Thumb library.

     *       thumbmain.c  *
     #include <stdio.h>
     extern void arm_function(void);
     int main(void)
          printf("Hello from Thumb\n");
          printf("And goodbye from Thumb\n");
          return (0);
     *        armsub.c    *
     #include <stdio.h>
     void arm_function(void)
          printf("Hello and Goodbye from ARM\n");

Building the example

Follow these steps to compile and link the modules:

  1. To compile the Thumb code for interworking, type:

    armcc --thumb -c --debug --apcs=/interwork thumbmain.c -o thumbmain.o
  2. To compile the ARM code for interworking, type:

    armcc -c --debug --apcs=/interwork armsub.c -o armsub.o
  3. To link the object files, type:

    armlink thumbmain.o armsub.o -o thumbtoarm.axf

    Alternatively, to view the size of the interworking veneers, type:

    armlink armsub.o thumbmain.o -o thumbtoarm.axf --info=veneers
  4. Run the image using a compatible debugger with an appropriate debug target.

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