Skip to main content
Associate
April 26, 2026
Question

How can I use C++ with the generated code from CubeMX in the STM32CubeIDE for Visual Studio Code?

  • April 26, 2026
  • 2 replies
  • 111 views

In STM32CubeIDE, I can compile C++ code in the project. The CMake file generated for the VSCode extension doesn't work with C++. Is there a way to use C++ code with less hassle than trying to get around this by hand?

2 replies

Cartu38 OpenDev
Graduate II
April 26, 2026

@jsteezy 

C++ is supported for free.

CMake itself is agnostic. It relies on file(s) extension(s) to pass right compiler settings.

STM32Cube for Visual Studio Code requires no trick nor magic to get C++ running.

jsteezyAuthor
Associate
April 26, 2026

Ok. So You're saying that if I follow the typical process:

  • STMCubeMX -> generate code for CMake
  • Open root in VSCode
  • VSCode notification -> Select "Configure discovered CMake projects"
  • STM32CubeIDE for VSCode extension -> setup STMCube project -> toolchain GCC
  • Build by clicking gear button

Then I should be able to make my main.c a main.cpp, and it will compile?

Cartu38 OpenDev
Graduate II
April 27, 2026

@jsteezy 
STM32CubeMX is only generating C projects. C++ has to be your own addition. Maybe https://isocpp.org/wiki/faq/mixing-c-and-cpp