SDK with C++ S32DS project

cancel
Showing results for 
Search instead for 
Did you mean: 

SDK with C++ S32DS project

587 Views
Contributor I

Hi,

how can I create a C++ S32DS project using S32 SDK?

(i'm trying on S32K144 EVB)

thanks

Nicola

Labels (1)
Tags (2)
0 Kudos
7 Replies

18 Views
Contributor II

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.

0 Kudos

18 Views
Contributor I

Hi Travis,

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.

Cheers,

Zitong

0 Kudos

18 Views
Contributor III

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);

0 Kudos

18 Views
Contributor III

Hi,
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

void __libc_init_array(void);

void main(void)
{

 __libc_init_array();

  main_app();  //which is as described above

}

and now

cObject object(constructor params);

seems to be working fine.

0 Kudos

18 Views
Contributor I

Hi Martin,

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 

Cheers,

Zitong

0 Kudos

18 Views
NXP Employee
NXP Employee

Hi Nicola, 

unfortunately - using C++ with S32K SDK is not supported in S32DS. 

Jiri 

0 Kudos

18 Views
Contributor I

Hi Jiri,

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.

Many thanks,

Zitong

0 Kudos