cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to code in C++, as IOC tool won't update main.cpp but rather create a new main.c

Matth1
Associate III

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
Pavel A.
Evangelist III

> What would be the proper way to use C++?

The proper way to use C++ with CubeIDE is just three simple steps:

  1. 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).
  2. Leave all C files created by Cube as is, and let them be compiled in C mode,
  3. Call your C++ "main" from the main.c

If you want to use a different IDE, please say so.

Cartu38 OpenDev
Lead II

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.

Thanks!