Where is _libc_init_array() defined?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where is _libc_init_array() defined?

Jump to solution
1,323 Views
oscar_abn
Contributor I

Hello, 

I am working on the S32K344 microcontroller and I need to execute c++ code. After finding out c++ is not officially suported with and SDK project I tried to implement some of the workarounds explained in nxp community pages. 

In short, the steps are: create a C project with SDK, add C++ nature, rename main.c to main.cpp, change standard linker file to the linker file created in the project in project settings (see image).

Screenshot 2024-09-13 134701.png

 

 

 

After this steps I am able to build a project with main.cpp, however the objects declared outside of main are not executed or initialized. 

One solution i found to this problem is to include  __libc_init_array() at the beginning of main(). The problem now is that this function is not found. How can i add the library to solve this dependence? Is there any other solution to initialize objects outside of main in c++? Console output:

Building file: ../RTD/src/Clock_Ip_ExtOsc.c
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@RTD/src/Adc_Sar_Ip.args" -MMD -MP -MF"RTD/src/Clock_Ip_ExtOsc.d" -MT"RTD/src/Clock_Ip_ExtOsc.o" -o "RTD/src/Clock_Ip_ExtOsc.o" "../RTD/src/Clock_Ip_ExtOsc.c"
../src/main.cpp: In function 'int main()':
../src/main.cpp:59:2: error: '__libc_init_array' was not declared in this scope
59 | __libc_init_array();
| ^~~~~~~~~~~~~~~~~
make: *** [src/subdir.mk:20: src/main.o] Error 1
make: *** Waiting for unfinished jobs....

 

0 Kudos
Reply
1 Solution
1,259 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

_libc_init_array is part of STD C library (for example libc_nano.a). If you are using C++ you don't need link STD C Library and call _libc_init_array. 

View solution in original post

0 Kudos
Reply
1 Reply
1,260 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

_libc_init_array is part of STD C library (for example libc_nano.a). If you are using C++ you don't need link STD C Library and call _libc_init_array. 

0 Kudos
Reply