Proper way to code in C++, as IOC tool won't update main.cpp but rather create a new main.c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-12 8:48 AM
Hey everyone,
I'm trying to make a project in C++. I tried the trick to rename main.c to main.cpp with the right-click > rename function. It works, but then if I change the IOC with the config tool, it will create a new main.c with the proper settings (and ignore main.cpp).
What would be the proper way to use C++? Is there a setting to have main.cpp updated in case of a config change ?
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-12 12:36 PM
Many other thread on such topic. One is There is a plan to allow STM32cubeMX for generating main.cpp instead of .c only ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-12 9:33 AM
> What would be the proper way to use C++?
The proper way to use C++ with CubeIDE is just three simple steps:
- Put all your C++ code in your own files (and name the cpp files so that base name differs from any C file created by Cube. Thus, no "main.cpp" - choose a different base name).
- Leave all C files created by Cube as is, and let them be compiled in C mode,
- Call your C++ "main" from the main.c
If you want to use a different IDE, please say so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-12 12:36 PM
Many other thread on such topic. One is There is a plan to allow STM32cubeMX for generating main.cpp instead of .c only ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-13 2:41 AM
Thanks. Actually I now know my problem was with header files for C++ where I didn't properly added
#ifdef __cplusplus
before C++ code (e.g. extern "C", including C++ libraries, ...) . So the compiler not knowing it was supposed to be C++ showed an error.
I think I now managed to do the "bridge" between C and C++, and that is what most users do: leave main in C and from there call my C++ call that is in other files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-13 2:41 AM
Thanks!
