Skip to main content
Associate III
April 16, 2025
Question

C++ support in CubeMx

  • April 16, 2025
  • 2 replies
  • 910 views

Hello everyone,

I wanted to check if there is any updated information regarding when STM32CubeMX will officially enable generation and support of C++ code. Currently, I'm still relying on various workarounds to implement projects in C++, which unnecessarily complicates the development process.

Does anyone have new insights or know of an official roadmap from STMicroelectronics? 

Adding native C++ support would be a significant improvement, especially for higher performance STM32 microcontrollers like the STM32H7, STM32U5, etc. series. C++ enables better code organization through object-oriented programming, making it easier to manage complex projects.

2 replies

Ghofrane GSOURI
Technical Moderator
April 16, 2025

Hello @EniRot99 

STM32CubeIDE can help generate C++ projects. You can follow these steps to convert a CubeMX project to a C++ project:

1-Generate the CubeMX project.

2- Open the project  STM32CubeIDE

3- Right click on the project -->  Convert to C++ Project" option to add C++ nature to the project.

4- Rename "main.c" to "main.cpp".

5- Adjust the project properties to use the C++ compiler and set the desired C++ standard

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
EniRot99Author
Associate III
April 16, 2025

Hi @Ghofrane GSOURI 

yes this is a workaround I already did. The problem is, when you have to change a setting in CubeMX or expand the application, for example, adding a new peripheral CubeMX will overwrite your "main.cpp" with a newly generated "main.c". This makes the workflow tedious, as you constantly have to re-merge your previous C++ adaptations back into the project.

What we're really looking for is native C++ support directly in CubeMX. Ideally, CubeMX should directly generate ".cpp" files, so we don't have to manually adjust the code after every regeneration.

TDK
Super User
April 16, 2025

Keep it as main.c and put your C++ code in another file. This is how it is meant to be done and avoids the annoyances you mention.

CubeMX is created to generate C code.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Pavel A.
Super User
April 16, 2025

There is another, simpler, cleaner way, it has been discussed in this forum ad nauseum.

It is that you simply convert the project generated by Cube to C++. Then you simply develop your object oriented application in C++, and let the Cube do its business as usual.

Young C++ developers are invited to review their C++ classes and refresh on the extern "C" construct. No need to rename anything. That's all. It works.