cancel
Showing results for 
Search instead for 
Did you mean: 

SWV ITM (printf) is not working with main.cpp(c++) but with main.c it works like a charm.

Akuks.1
Associate II

Okay basically i have two question,

[1]

SWV ITM (printf) is not working with main.cpp(c++) but with main.c it works as a charm. The culprit seems to be is main.cpp but i have no idea how to make it work there.

[2]

 The project is converted to C++ even though it produces main.c files instead of main.cpp. So i have to manually rename it to main.cpp . When ever i make any changes to .ioc the cubeMx inside of the cubeIDE produces the main.c instead of a c++. Is there any way to automatically generate source files in cpp extension because manually renaming it often leads to human error. Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

Sure you can. You could, for example, create something like "appmain.cpp" with a function "appmain(void)". In appmain.h you provide the function prototype:

#ifdef __cplusplus
   extern "C" {
#endif
 
void appmain( void );
 
#ifdef __cpluscplus
   }
#endif

Then from main(), call your appmain() to then call C++ functions, instantiate class instances, etc.

View solution in original post

3 REPLIES 3
Pavel A.
Evangelist III

If you just leave the generated main.c as is, both self-inflicted issues would disappear.

Thats very basic, but couldn't do it as the project has a library that was written in c++.

Sure you can. You could, for example, create something like "appmain.cpp" with a function "appmain(void)". In appmain.h you provide the function prototype:

#ifdef __cplusplus
   extern "C" {
#endif
 
void appmain( void );
 
#ifdef __cpluscplus
   }
#endif

Then from main(), call your appmain() to then call C++ functions, instantiate class instances, etc.