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");
          arm_function();
          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.
Related concepts
4.6 Assembly language interworking example
4.7 Interworking using veneers
4.9 C, C++, and assembly language interworking using veneers
Related information
--apcs=qualifier...qualifier compiler option
-c compiler option
--debug, --no_debug compiler options
-o filename compiler option
--thumb compiler option
--info=topic[,topic,...] linker option
--output=filename linker option
Non-ConfidentialPDF file icon PDF versionARM DUI0471K
Copyright © 2010-2014 ARM. All rights reserved.