Creating C++ STM32CubeMX-based Projects

Sysprogs forums Forums VisualGDB Creating C++ STM32CubeMX-based Projects

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #29460
    nahumb
    Participant

    Hi,

    I have been able to create a C STM32CubeMX based project and it runs great.

    I would like now to add c++ code (e.g. classes).

    I add a new header file with

    #ifdef __cplusplus
    extern “C” {
    #endif

    class MyClass {    };

    #ifdef __cplusplus
    }
    #endif

    But I get an “unknown type name ‘class'” errors.

    I did not find any instruction how to start or configure the project as a c++ project.

    Can it be done? Can you please assist.

    Thanks,

    Nahum.

    #29469
    support
    Keymaster

    Hi,

    This is to be expected. The STM32CubeMX tool generates Plain C files, so placing C++ code in them will result in errors. You can still add .cpp files to the STM32CubeMX-generated projects as shown in our STM32CubeMX tutorial, however it will require carefully partitioning the code into Plain C and C++ parts, and declaring the functions that need to be visible from both parts with extern “C”.

    As an alternative, please consider using the regular VisualGDB Embedded Project Wizard that can generate a C++ main file instead.

    #29470
    nahumb
    Participant

    Thank you. Will give it a try.

    Nahum.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.