Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

How to use C++ in CooCox CoIDE

$
0
0

CoIDE supports only C language by default. *.cpp or *.C (a capital letter) files in CoIDE projects will not be compiled. What a pity!

 Fortunately there are always more solutions than questions on earth. Now you can use C++ in CoIDE with just several modifications.

 Here are the steps:

 1.Edit build.xml so that *.cpp files can be compiled.

<fileset dir=".">

<include name="**/*.c"/>

<include name="**/*.cpp"/>

<include name="**/*.s"/>

</fileset>

 2.Edit link.ld so that the linker can recognize several segments needed by C++.

/* Section Definitions */

SECTIONS

{

  .text :

    {

        KEEP(*(.isr_vector .isr_vector.*))

        *(.text .text.* .gnu.linkonce.t.*)       

        *(.glue_7t) *(.glue_7)                      

        *(.rodata .rodata* .gnu.linkonce.r.*)  

         /* C++ Static constructors/destructors (eabi) */

       . = ALIGN(4);

       KEEP(*(.init))

        . = ALIGN(4);

       __preinit_array_start = .;

       KEEP (*(.preinit_array))

       __preinit_array_end = .;

      . = ALIGN(4);

       __init_array_start = .;

       KEEP (*(SORT(.init_array.*)))

       KEEP (*(.init_array))

       __init_array_end = .;

      = ALIGN(4);

       KEEP(*(.fini))

       . = ALIGN(4);

       __fini_array_start = .;

       KEEP (*(.fini_array))

       KEEP (*(SORT(.fini_array.*)))

       __fini_array_end = .;

       /* C++ Static constructors/destructors (elf) */

       . = ALIGN(4);

       _ctor_start = .;

       KEEP (*crtbegin.o(.ctors))

       KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))

       KEEP (*(SORT(.ctors.*)))

       KEEP (*crtend.o(.ctors))

       _ctor_end = .;

       = ALIGN(4);

       KEEP (*crtbegin.o(.dtors))

       KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))

       KEEP (*(SORT(.dtors.*)))

       KEEP (*crtend.o(.dtors))                       

    } > rom

   .ARM.extab :

    {

        *(.ARM.extab* .gnu.linkonce.armextab.*)

} > rom

    /* stack section */

    .co_stack (NOLOAD):

    {

   . = ALIGN(8);

        *(.co_stack .co_stack.*)

    } > ram

    __exidx_start = .;

    .ARM.exidx :

    {

        *(.ARM.exidx* .gnu.linkonce.armexidx.*)

    } > rom

    __exidx_end = .;

   = ALIGN(4);

    _end = . ;

}

3.Edit startup file so that it calls constructors of static objects.

externunsignedlong __preinit_array_start;

externunsignedlong __preinit_array_end;

externunsignedlong __init_array_start;

externunsignedlong __init_array_end;

externunsignedlong _ctor_start;

externunsignedlong _ctor_end;

staticvoidcall_constructors(unsignedlong *start, unsignedlong *end) __attribute__((noinline));

staticvoidcall_constructors(unsignedlong *start, unsignedlong *end)

{

  unsignedlong *i;

  void (*funcptr)();

  for ( i = start; i < end; i++)

  {

    funcptr=(void (*)())(*i);

    funcptr();

  }

}

voidDefault_Reset_Handler(void)

{

  /* Setup the microcontroller system. */

  SystemInit();

   //Initialize CoOS (in order the new/delete operators to work properly

  //prior to calling constructors). Comment it out if you don't use CoOS!

  CoInitOS();

   //Call C++ global constructors

  call_constructors(&__preinit_array_start, &__preinit_array_end);

  call_constructors(&__init_array_start, &__init_array_end);

  call_constructors(&_ctor_start, &_ctor_end);

  /* Call the application's entry point.*/

  main();

}

4.Select component C Library and Retarget printf from the Repository View, then comment out the line below to avoid redefinition of _impure_ptr.

struct _reent *_impure_ptr = &r;

 5.In project's Configuration, add two entries to "Linked Libraries" pane: libstdc++ and libsupc++, which can be found in GCC tool chain lib.

 

Sources:

http://www.coocox.org/Forum/topic.php?id=730

http://www.coocox.org/Forum/topic.php?id=873


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>