cancel
Showing results for 
Search instead for 
Did you mean: 

Cube32 feature request, need to handle CPP files.

Harvey White
Senior III

The support of CPP architectures in Cube32 is limited. While it would be nice if Cube32MX actually had CPP libraries, that's a long step.

It's very possible, however, to integrate a C++ layer on top of the existing code, where C++ routines call C routines.

However the process is limited by one feature in Cube32MX, and that is the dependence on main.c. How about a very small rewrite so that once there *is* a main.cpp, Cube32MX can make changes to it. Shouldn't be hard to do. Change main.c if it exists in the project, if it doesn't, then look for main.cpp and change it.

This will stop errors caused by forgetting to rename main.cpp back to main.c so that adjustments can be made, and then back from c to cpp.

19 REPLIES 19

Thanks for the fast reply! That's a good hint and I'm gonna give it a try.

Unfortunately I don't see any possibility to exclude a single file from being compiled with the c++ comiler only. I could exclude the whole directory - but this makes all files of the specific directory unavailable for all languages/compilers...

But that's another topic so I may open a new thread for this question. Also switching to CMake may be an option...

TouchGFX is really a pain to setup - I haven't achieved it yet. But the Designer looks like a nice tool to easily create/change GUIs.

There's several options,

First, for completeness, you can go to the properties of each file (alt-enter) and check exclude file from build. That's for all compilers, I think, although you may want to try it. Included for completeness.

Secondly, take the file and put it in its own directory. Include that directory only in the appropriate compiler. C++ can handle C syntax, C compiler doesn't understand class structures, for instance.

For GFX (it was a while back), I seem to remember such difficulties. I tried renaming all the C files C++, and that didn't work well because of how they had embedded everything.

Perhaps you could put a very simple link file, which you go through (and indirect kind of call). Then let the C compiler deal with that only. The C++ compiler gets the C++ code.

Again, separate directories may be a key.

I found the mistake...

I was still including the c++ header in a .c file. This caused the C linkage error.

Excellent, glad you found it. C compilers hate C++ code......

By the way, in *.cpp files the #ifdef __cplusplus is completely useless and the extern "C" is also not necessary as the function is already declared as such in a header file.

I never analyzed it, but I thought some parts were needed to make the C compiler happy.

I'll give it a try.

So you're saying that any C function can call a C++ function?

Curious

I'm saying that the *.cpp files are not shared - they are just for C++ compiler. The C compiler gets just the shared *.hpp files.

Harvey White
Senior III

I understand. That, of course, explains why the class definitions in .hpp files cause the C compiler to throw up all over the listing. Have you a suggestion to fix that other than making sure that the path to that file is only in the C++ file paths?

Piranha
Chief II

The *.c files should include only those *.hpp files, which are specifically made to be shareable between the C/C++ and use the #ifdef __cplusplus and extern "C" appropriately.

Gaston
Senior

However the process is limited by one feature in Cube32MX, and that is the dependence on main.c. How about a very small rewrite so that once there *is* a main.cpp, Cube32MX can make changes to it. Shouldn't be hard to do. Change main.c if it exists in the project, if it doesn't, then look for main.cpp and change it.

It must be very difficult, extremely complicated.
After 5 years of this post, we are still renaming main.c to main.cpp...