2020-09-13 12:30 PM
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
2020-09-13 01:06 PM
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++;}
2020-09-13 01:49 PM
aha, I did fix that one after the screenshot was taken LOL
will try your steps.