Re: Class constructor doesn't execute
Uwe Bonnes <bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org> Mon, 5 Dec 2016 14:59:23 +0100
| Newsgroups | gmane.comp.hardware.microcontrollers.ethernut |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "Krzysztof" == Krzysztof Sawicki <[email protected]> writes: Krzysztof> Hi, recently I tried some C++ with NutOS and realised that Krzysztof> class' constructors are not executed. I did some research and Krzysztof> realised that following code fixes this issue: Krzysztof> in linker script add: .preinit_array : { PROVIDE_HIDDEN Krzysztof> (__preinit_array_start = .); KEEP (*(.preinit_array*)) Krzysztof> PROVIDE_HIDDEN (__preinit_array_end = .); } > FLASH0 Krzysztof> .init_array : { PROVIDE_HIDDEN (__init_array_start = Krzysztof> .); KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array*)) Krzysztof> PROVIDE_HIDDEN (__init_array_end = .); } > FLASH0 Krzysztof> .fini_array : { PROVIDE_HIDDEN (__fini_array_start = Krzysztof> .); KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array*)) Krzysztof> PROVIDE_HIDDEN (__fini_array_end = .); } > FLASH0 Krzysztof> in main() at the beginning add: /* Call static constructors Krzysztof> */ asm("bl __libc_init_array"); Krzysztof> and anywhere in the code: Krzysztof> extern "C" { void *__dso_handle = NULL; void _init(void){} } Why does app/cppdemo build? What of these prerequisites is Gnu specific, what is processor specific and what is generic. I think anything generic can be added guarded with #if defined(__cpluplus) Any ideas? Bye -- Uwe Bonnes bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 1623569 ------- Fax. 06151 1623305 --------- _______________________________________________ http://lists.egnite.de/mailman/listinfo/en-nut-discussion