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).
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....
Solved! Go to Solution.
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.
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.