2023-05-26 12:40 PM
Hi, I'm trying to make a c++ project for STM32CubeIDE using the STM32CubeMX.
However there doesn't seem to be any c++ option, is there something I'm missing or is the software just not made for it?
Solved! Go to Solution.
2023-05-26 12:49 PM
After opening the project in CubeIDE right click on it and select "Convert to C++".
This won't change the code generated by CubeMX to C++. All these files remain C, this is normal, you don't want to change it. Use C++ in source files that you add.
2023-05-26 12:48 PM
Ok so my question still stands, however there's a way around it? you can make new project from existing ioc file, which lets you make a c++ project.
it's just kinda upside down approach ;-;, maybe you're not supposed to use cubemx anymore? this all is very confusing.
2023-05-26 12:49 PM
After opening the project in CubeIDE right click on it and select "Convert to C++".
This won't change the code generated by CubeMX to C++. All these files remain C, this is normal, you don't want to change it. Use C++ in source files that you add.
2023-05-26 12:56 PM
CubeMX simply is not aware of C++. It always creates its stuff in plain C, and it works in both C and C++ projects. Ability to co-exist with C code is a fundamental feature of C++.
2023-05-26 01:29 PM
ok but this still makes a main.c file?
so i still have to make leaps to actually add a cpp file in that would compile properly?
2023-05-26 03:23 PM
Yeah that is fair. The thing is that makes all this really annoying is it generates main.c. and if I'd want to make a project in which I can change stuff in CubeMX, I can't turn it into main.cpp.
So now in order to just use any of my existing libraries I have to have main.c which doesn't contain main function and main.cpp which does.
Or have a c wrapper for c++ code which also isn't as nice.
Ig wanting the main.c to just change to cpp is too much.
2023-05-27 02:11 PM
Just add your own cpp file(s) where you use these existing c++ libraries.
The main function remains in the main.c file, it is already good as it is.
Any global variable defined in main.c and other generated c files can be easily reached from cpp files via extern "C", as you of course know.
C wrapper for c++ code? Why this may be needed? Again, in most cases a simple extern "C" is enough.
> wanting the main.c to just change to cpp is too much
Short answer - yes, too much )) This does not add real value but creates extra work to others.