2024-12-02 06:13 AM - edited 2024-12-03 02:41 AM
Hi,
How to tell CubeIDE to compile specific *.c files with C++ compiler ?
Changing suffix from *.c to *.cpp is not an option.
[edit] Changing the suffix from *.c to *.cpp is the least preferred option.
Thank you
2024-12-03 04:29 AM
Okay, you did not. Thanks.
2024-12-03 09:50 AM - edited 2024-12-03 10:26 AM
2024-12-04 12:18 AM - edited 2024-12-04 12:51 AM
And what happened? Can you show your build log?
2024-12-05 05:34 AM
Here, the original C recipe is used despite setting C++ in mapping.
I''ll come back later with a document describing what is going on.
2024-12-06 02:21 AM - edited 2024-12-06 02:46 AM
I created a simple example project using STM32CubeMX 6.12.1.
I opened it in STM32CubeIDE 1.16.0 and converted it to cpp (rightclick convert to cpp). I added 2 source files:
I tried various ways to override the file settings and language mappings and even editing the .cproject xml file manually (copying the settings of the cpp file from the xml). It doesn't work. So strange. The only thing that worked was modifying the build command to g++. But this doesn't take any of the project wide C++ settings and defines. It even compiles it with -std=gnu11. So this is ugly but it works.
I tried something interesting. The properties of the file test.c showed "C Source File" regardless of my language mapping. So Eclipse uses some type of pattern filter based on file extension to determine the type. I was able to override this:
Now it shows the correct type. And the language mapping tab is automatically set to "C++ Source File". However in build it still shows the C compiler. Even after deleting the source file and adding it again. So it seems Eclipse uses the associated source type only for some purposes (syntax highlighting?) and not for actual compiler language selection. And language mapping is ignored.
So "type" doesn't do anything.
my test.c source file:
#ifdef __cplusplus
#warning "test.c compiled as C++"
#else
#warning "test.c compiled as C"
#endif
Edit:
I also added a file "test.test" and made an association with C++. It doesn't compile and it doesn't highlight syntax. So I have to clue what eclipse uses "type" for.
2024-12-06 04:21 AM - edited 2024-12-06 06:29 AM
Thank you very much for this. Great reference.
"The only thing that worked was modifying the build command to g++. But this doesn't take any of the project wide C++ settings and defines."
I am also trying to find out if it is possible to access a build variable, if there is such, that hold all C++ or C options.