2022-08-18 05:18 PM
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.
Solved! Go to Solution.
2022-08-19 06:58 AM
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.
2022-08-18 06:24 PM
If you just leave the generated main.c as is, both self-inflicted issues would disappear.
2022-08-18 11:17 PM
Thats very basic, but couldn't do it as the project has a library that was written in c++.
2022-08-19 06:58 AM
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.