C++ support

From ERIKA WIKI
Revision as of 16:19, 8 August 2018 by Claudio (talk | contribs) (Created page with "= Introduction = Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, it has <u>experimental</u> support to link applications implem...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, it has experimental support to link applications implemented using the C++ language.

Basic support

The .cpp file extension is automatically recognized and handled by the Makefiles.

Put in the OIL file the following information:

  CFLAGS = "-std=c++11";
  CFLAGS = "-fno-exceptions";
  CFLAGS = "-mstrict-align";

Moreover, embed through the following braces any C symbol that must be linked to the application (e.g. idle_hook, tasks, etc.)

  extern "C"{
     //...
  }

The main function can be left outside the braces.

This must be done also for external libraries. In case of Jailhouse, for example, the inmate library must be modified as shown here.

This is the basic list of the features supported:

  • Normal classes
  • Template metaprogramming
  • C++11: lambda expressions, type deduction (i.e. auto)

STL support

If you also want to support the STL features provided by the bare-metal newlib toolchain (i.e. the one provided by Linaro's bare-metal gcc toolchain), you have to modify the linker script to set the end symbol:

  .data   : {
    *(.data)
  }
  . = ALIGN(8);
  /* "end" is used by newlib's syscalls */
  PROVIDE(end = .);
  . = ALIGN(16);
  stack_bottom = .;
  . = ALIGN(4096);
  . = . + 0x10000;
  stack_top = .;

Then, add the following information to the OIL file:

  CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/7.2.1/";
  CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/7.2.1/aarch64-elf/";
  CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/libc/usr/include/";
  LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/libc/usr/lib";
  LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/lib/";  
  LIBS = "-l:libc.a";
  LIBS = "-l:libgcc.a";
  LIBS = "-l:librdimon.a";
  LIBS = "-l:libsupc++.a";