Support for C + + by the ultra lightweight operating system oneos Lite


brief introduction

c++Component is to support compilationc++Source file. The component puts the constructor of the global object into the specified segment address to supportc++Normal use and operation of.

becauseOneOS-LiteIt’s very streamlinedRTOSThe system is therefore providedC++The support is relatively simple.

staycpp_init.cSource file, doneC++System initialization:

OS_WEAK int cpp_init(void)

    typedef void(*pfunc)();
    extern pfunc __ctors_start__[];
    extern pfunc __ctors_end__[];
    pfunc *p;

    for (p = __ctors_start__; p < __ctors_end__; p++)

    return 0;

Among them__ctors_start__and__ctors_end__Location specified in link script:

PROVIDE(__ctors_start__ = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE(__ctors_end__ = .);

Visible, incpp_initFunction, the constructor of the global object is linked one by one to the segment to which the linked file is assigned. then,OS_CMPOENT_INITyesOneOS-LiteComponent initialization macro, which willcpp_initFunction is placed at the position of component initialization for initialization.

  1. __ctors_start__: the starting address of the C + + global constructor segment
  2. __ctors_end__: the end address of the C + + global constructor segment

Graphical configuration

(Top) → Components→ Cplusplus
[*] cplusplus

Simple experience

#Include < iostream > // include the header file iostream
using namespace std;  // Use namespace STD

extern "C" 
int test(void);
int test( )
    cout<<"This is a C++ program!";
    return 0;

Edit ac++File, and inmain.cIn file, calltestFunction, compile and run, you can use the serial port to print the information.

be careful

MicroLIBI won’t support itc++, you need tooptionsinUse MicroLIBUncheck.

supportc++Will increase the size of the programramandflash

Finally, if you need to usec++code. Well, pleaseSConscriptMiddle, putcppAdd files to the compilation system.

src = Glob('*.c') + Glob('*.cpp')

Follow & & contact



Quoted from: