Forum: System Workbench for STM32

serious bug. cubeMx generation issue under C++

The flaw described here applies to both the libraries as well as CubeMx generation under C++.

1. CubeMX and the libraries are currently aligned with “C” compilation and linking (eg no name mangling).
2. For the existing libraries and generated code to WORK in both “C” and “C++” ALL of the libraries and the generated code’s include files requires that the function prototypes in the header files MUST be bracketed by the following construction to insure that the linkers will blend “C” and “C++” properly.

  1. ifdef __cplusplus

extern “C” {

  1. endif


// “C” compliant function prototypes

  1. ifdef __cplusplus

}

  1. endif // __cplusplus


This is an imperative and requires updating of cubeMX AND all libraries. With this construct added, all of the libraries and generated code will work as they do now when the remainder of the application is compiled under C++ in order to use class, inheritance and template functionality.

This will help significantly when making C++ classes portable across many embedded systems.

Ah, they already do include this (I use C++ in CubeMX projects right now - as in today).

You will however find life much easier if you confine yourself to naming C++ _exclusive_ headers to *.hpp (or similar)
There are several posts here about converting a project to C++