Using c plus plus methods in FRDMK22 application

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

Using c plus plus methods in FRDMK22 application

602 Views
christophertsch
Contributor III

I prefer coding using an object oriented language and have looked for how to use C++ in KSDK and process expert based applications using the Kinetis Design Studio. One generic suggestion I found is to use the C++ compiler for everything but that does not seem possible or at least very straightforward using Eclipse/KDS. Does anyone have suggestions/examples of calling a class method from the KSDK/process expert generated C files? Many thanks!

Labels (1)
Tags (5)
2 Replies

435 Views
ndavies
Contributor V

KDS uses the GCC compiler. It will easily accept both C++ and C code. We do most of our coding in C++ with some C driver files. We only use the SDK to generate sample code we then recode as C++. So I can't help you with the SDK.

We have Main() in a CPP file, this generates the correct initialization for C++. You also need to declare your C functions as extern "C".  The names won't then get mangled by the C++ compiler and the linker can correctly find them.

0 Kudos

435 Views
christophertsch
Contributor III

Norm, thanks for your quick response. It was helpful. I am a bit of a noobie so I am not quite ready to use the SDK for an example to be used in another project. I figured out one way of getting KDS to use G++ for all C files but that really messed things up with the various other C files in the SDK. Then I tried to rename main.c to main.cpp but for some reason the G++ compiler could not find the SDK header files like “cpu.h”.

I think I can make a “mymain.cpp” that uses the extern “C” construct to make a “mymain” function that can be called from the main in main.c. In Mymain.cpp I can call whatever methods and define whatever class instances I need and still not mess with the code generated by the SDK/process expert.

0 Kudos