I am also really curious about this. In some applications it is easier to wire and maintain cleaner bug free code using basic object oriented principles that are much easier in C++. Having this supported more directly without all the steps would make life quite a bit easier.
I would prefer to use NXP tools, but I fee like this limits me.
Please refer to Martin's instructions to build a C++ application project that is compatible with your C code. It worked for me with two minor downsides:
(1) You have to maintain your generated code in another C application project and copy paste them to your C++ project.
(2) Setting up the included path for the C++ project could be a pain in the beginning. Maybe there is an easier way to do it.
What worked for me is, that I created regular C project with SDK, then File / New / Convert to a C/C++ project
Then you have to go to project properties, C/C++ build / settings / Standard S32DS C compiler / includes , and copy necessary lines and paste them into C++ compiler/includes
Next step - create C++ project without SDK and copy it's linker files over those in project with SDK
Then I created main_app.cpp with function main_app() defined as extern "c" and called main_app() from main() function in main.c and then I can call C++ classes from main_app()
Now I am able to compile it and application seems to be working, I can also use processor expert etc ...
The only problem I found is that using constructors like this:
cObject object(constructor params); is not working like expected
I have to use
cObject *object = new cObject(constructor params);
I may have found what to do, so that you don't have to use new() with constructors
just add __libc_init_array(); call to main.c
main_app(); //which is as described above
cObject object(constructor params);
seems to be working fine.
Thanks for your reply! I took about the same path to create a C++ project with S32 SDK in C.
I followed this post to wrap C++ objects so that they could be used in C code: Tutorial: HowTo integrate a C++ library/class into a C programm - Teddy Engineering GmbH
I've also read that if you are using freeRTOS, it is recommended to use ```pvPortMalloc()``` and ```vPortFree()``` to override ```new``` and ```delete```: New object not created properly - FreeRTOS
A follow-up question if I may: if I really need to use some C++ code in an S32K project, what would be your suggestions? So far I've thought of the following approaches that might work:
1. Using a different compiler other than S32K DS.
2. Build the C++ code into a C-compatible static library (with wrappers and all) and add it to the C project in S32K DS.