Showing results for 
Search instead for 
Did you mean: 

There is a plan to allow STM32cubeMX for generating main.cpp instead of .c only ?

Associate III

Hi, I know this question have been asked several time, but STM32CubeIDE and STM32CubeMx are only generating .c file... this is very frustriating, time consuming and source of multiples error when working with cpp environment. We have to manually rename .c to .cpp file and vice et versa after each modification... this is so 1990 workflow.

Does this implementation have been planned in the future or shall I forget about it ?

Thanks for your reply.


I'm not opposing anything. I'm just pragmatic trying to work smoothly with material I've.

I'm ok could be more flexible and would be happy about for sure. On the other side sounds like to me like automation "drawback". Automation is very helpful but forcing some structure / way of working. Asking for automation and flexibility is most often leading to gaz plant (increasing options & buttons count, ... and in sync. bugs ...).

As summary what's important to me today is I'm not stucked despite I'm taking benefit of automation.

Thanks for your comments. 😉

Associate III

My best workaround for the moment in eclipse STM32CubeIDE :

1) create main.cpp and main.hpp file right next to main.c and main.h (it's ugly, I know it)

1.1) don't forget to change your include "main.h" to "main.hpp"

2) exclude main.c from the compilation (right click on it > resource config > Exclude from build > check debug and release) > OK )

3) for any change made to you cubeMX config and applied to the file main.c (and main.h) you can use the compare function in eclipse to maintain the two files consistent

4 ) Select main.h and main.hpp for instance, and right clic on them > Compare with > Each other.

Associate II


jose luu
Associate III

Workaround starting with CubeMX 6.9.0 in Project Manager -> Code generator -> After code generation



Specify a .bat script located in Core/Src containing:



set SCRIPT_DIR=%~dp0%
copy main.c main.cpp
del main.c



In -> Before code generation you also need the converse script, otherwise CubeMX will regenerate from scratch and will not take into account the modifications you may have done


set SCRIPT_DIR=%~dp0%
copy main.cpp main.c
del main.cpp



As of 6.9.2 the script path as to be absolute (eg. C:\Users\...)