cancel
Showing results for 
Search instead for 
Did you mean: 

Switching a STM32CubeIDE C project to C++ - need guidance, unable to make it work

rbarris
Associate II

I have a project made with STM32CubeIDE, created with the new project wizard, for the Nucleo H745ZI board. Everything is working great.

Now I have some libraries I want to add that are written in C++.

I recognize that the Cube/HAL side of things is all C, I don't have any expectations that there's a magic checkbox that changes all of those subsystems to be C++. I would be perfectly happy if main.c stayed C-based and I had to set up a few extern "C" functions for main.c to call out to.

But, so far I have been 100% unable, using IDE version 1.4.2 on macOS, to add a single CPP file to the project and get it to compile and link in.

I have hit the "Convert to C++" menu command on the top level project. I then imported a source folder ("cppsrc") from the file system and I can see "foo.cpp" in the project hierarchy.

Observations:

a) rebuilding the project, foo.cpp is never mentioned in the build log.

b) the editor has some feedback blips saying that it can't find the C++ style includes and that there's a syntax error around the "private" keyword

I had taken an earlier approach where I tried to go through the IDE "New source file" wizard to add a cpp file, that way crashed the IDE a couple times and I gave up on it. This path of doing an import from the file system doesn't yield any fireworks, but the IDE isn't trying to compile the code.

If someone could show me known-good steps for taking a Cube/HAL C-based project in STM32CubeIDE and starting to add C++ code to it, I would be quite grateful. Or, perhaps it is busted and then this should be a bug report.

curious,Rob

0693W000003RV3MQAW.png

2 REPLIES 2
TDK
Guru

If you're adding new source files, place them in the same directory as existing source files, or add that directory as a source directory within the project (Project Properties -> C/C++ General -> Paths and Symbols -> Source Location.

> there's a syntax error around the "private" keyword

That's because there is a syntax error. This is not a valid function definition:

void inc_foo(m_foo++;)

Perhaps you wanted this:

void inc_foo() {m_foo++;}

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

aha, I did fix that one after the screenshot was taken LOL

will try your steps.