Where is _libc_init_array() defined?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Where is _libc_init_array() defined?

跳至解决方案
1,478 次查看
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 项奖励
回复
1 解答
1,414 次查看
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 项奖励
回复
1 回复
1,415 次查看
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 项奖励
回复