Skip to main content
Explorer
October 6, 2025
Question

How to Create STM32 C++ project in STM32 VS Code?

  • October 6, 2025
  • 2 replies
  • 476 views

I am able to create C++ project in STM32CubeIDE, like so:

kaosad_0-1759734935131.png

However, I can't find a way to do the same in STM32 VS Code. Is there such a feature in VS Code for STM32?

    This topic has been closed for replies.

    2 replies

    Graduate II
    October 6, 2025

    @kaosad,

    Considering STM32CubeIDE for Visual Studio Code solution, no C/C++ concerns to get.
    This solution relies on CMake as build system. Related toolchain file is both C and C++ capable. CMake is then managing the stuff properly for you taking care based on file extensions (.c or .cpp).

    Let's start from empty project without any worries here:

    Cartu38OpenDev_0-1759737912623.png

    By default main.c template is promoted. Just rename it to main.cpp and update CMakeLists.txt reference in sync. It will work !

    Cartu38OpenDev_1-1759738155643.png

    Cartu38OpenDev_2-1759738194727.png

    kaosadAuthor
    Explorer
    October 6, 2025

    Thanks. But that would create an empty project. I am looking for a way to create a C++ STM32CubeMX project just like what STM32CubeIDE is able to do.

    Graduate II
    October 6, 2025

    @kaosad 

    Your question is bit unclear to me to be fair.
    STM32CubeIDE is supporting collection of project creation modes (empty, from examples, MX, from binary, ...).

    Your first post is promoting STM32CubeIDE empty project GUI. I've answered about very same feature.

    If you're looking for a STM32CubeMX, please do it but no C++ option has never been supported here.

    Such said let's proceed very same:

    • Generate a STM32CubeMX project
    • Add it to VSCode workspace
    • Wait a bit for magic to run
    • Move main.c to main.cpp and u^pdate CMakeLists.txt file in sync.

    Just be aware at next code updqte triggered from STM32CubeMX ... main.c may come back. STM32CubeMX has never generated a main.cpp.

    Technical Moderator
    October 6, 2025

    Hello @kaosad and welcome to the Community

    You can refer to this article contains steps on how to add post build commands in VS Code:

    kaosadAuthor
    Explorer
    October 6, 2025

    Thanks for the useful article. Does STM32 VSCode provide a feature that can create C++ STM32CubeMX project without needing to meddle with the CMake script, just like STM32CubeIDE, which does not need any meddling with the Make script?

    Graduate II
    October 6, 2025

    Nope, at that time you have to dig into the CMake project by your own.

    I'm not aware of STMicroelectronics' plans here, but possibly they are eager to listen to our requests/suggestions here. What would help you the most here? Feel free to share your pain and wishes! If you're not trying, nothing may happen.