cancel
Showing results for 
Search instead for 
Did you mean: 

C++ Project that creates C main file

Gaston
Associate III

Hi,

If I create a C++ STM32CubeIDE project the main generated file is a C file (main.c) and I have to rename this to main.cpp every time I update pinmux, drivers, etc in order to call C++ functions. I think it's not an usual workflow but could anyone confirm this?

gaston

13 REPLIES 13

Okay

If you feel a post has answered your question, please click "Accept as Solution".

Right. CMSIS/HAL/LL can live well in the common subset of C and C++, but adding real C++ user code easily is hindered by the wrong file name extension main.c, nothing more or less.

KnarfB

Pavel A.
Evangelist III

> In fact it is the opposite. Using extern C allows you to call C functions from C++.

And also declare C++ functions callable from C and global variables that can be referred from C.

Gaston
Associate III

I think we should better understand how this works:

https://www.geeksforgeeks.org/extern-c-in-c/

My suggestion is clear and I have also provided the case of MCUXpresso, an environment very similar to STM32Cube, which solves this issue easy and efficiently.

Please, any feedback from ST side?