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-02 06:24 AM
@ferro wrote:Changing suffix from *.c to *.cpp is not an option.
Why not? Seems misleading to name it .c when it's actually C++ ?
Anyhow, Could you just #include the .c file in a .cpp file, and exclude the .c file from build?
2024-12-02 06:32 AM
Thanks for prompt reply.
No, files are writen in C and want to compile with C++ compiler.
"Could you just #include the .c file in a .cpp file, and exclude the .c file from build?"
Good idea but I perefere to set it as a flag in project properties. In Keil uVision IDE you right click on a file and set the option to build it as C or C++.
2024-12-02 06:39 AM
If you right-click the file and choose 'Properties', there's this:
Looks like generic Eclipse ?
2024-12-02 07:15 AM
"If you right-click the file and choose 'Properties', there's this:"
Thanks. I set C++ there but adc.c is still treated as C.
Hm, Maybe clue is in what is writen at the bottom - seems that it is not per file.
If you can be bothered, could you try on your side, please ?
2024-12-02 01:31 PM - edited 2024-12-02 01:36 PM
@ferro You already know about the -x switch of the GNU compiler. Use it. Compiler options can be modified per file.
/* disclaimer: this should not be taken as advise to mix C++ into Cube-generated main.c and compile Cube generated C files in C++ mode */
2024-12-02 10:24 PM
C is basically a subset of C++, so a C souces should compile within a C++ project without issues.
They linkage is quite different (including startup file).
I suppose you are aware of the name mangling issue and the extern "C" statement in this context.
2024-12-03 12:35 AM
Thanks for comment, I would like to know how to configure CubeIDE.
2024-12-03 12:46 AM
"Compiler options can be modified per file."
Where, how ?
2024-12-03 12:55 AM
You can exclude the c file from build and include it in a new cpp file. That's an ugly workaround.
@ferro wrote:"Compiler options can be modified per file."
Where, how ?
Rightclick the file. Click properties. Click C/C++ General. Click Language mappings. Then select GNU C++ from the drop down menus.