Calling C++ constructors at runtime init

Technical Note 16676

Arkitekturer:

ARM

Komponent:

linker

Uppdaterad:

2018-05-31 09:14

Introduction

The application runs into a random hardware fault if "Automatic runtime library selection" is disabled. (If the option is enabled, then is there no run-time error). 

Applies to

The project is built with any of the C++ dialects available in IAR Embedded Workbench for ARM version 6.x or newer.

Reason

When the project is linked with automatic selection of the IAR libraries, a call to the __iar_cstart_call_ctors method is added by the linker. See Project > Options > Linker > Library > "Automatic runtime library selection".

If the project is linked without the automatic library selection, the linker does not add a call to the __iar_cstart_call_ctors method.

Solution in IAR Embedded Workbench for ARM 6.10.2 and newer

Add a command line option at Project > Options > Linker > Extra Options. Enter this text:

--extra_init __iar_cstart_call_ctors

...in the text box.

Solution in IAR Embedded Workbench for ARM 6.10.1 and older

In this/these version(s) the linker does not have the --extra_init command line option.
The recommendation is to make an explicit function call, for example early in the main() function.

All product names are trademarks or registered trademarks of their respective owners.

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av iar.com rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.