2019-11-27 10:59 AM
I created a fresh C++ project and copied over some existing C files from another project. I then renamed them to .cpp and started porting them. First I renamed the system include files from foo.h to cfoo. With this, CubeIDE complains about cstdint not being found. It compiles the file with gcc -std=gnu11 instead of -std=gnu++14.
I tried setting the C Compiler to g++ but then CubeIDE chokes on C files using C++ keywords as identifiers.
I also tried renaming my own header files to .hpp (because the error occurs in the header file) but the error message remained the same.
error: cstdint: No such file or directory foo.hpp
How can I tell CubeIDE to compile the file with the correct compiler?
Solved! Go to Solution.
2019-11-29 10:25 AM
I renamed main.c to main.cpp and it compiled. Sure there will be some fine-tuning to do but it's one step forward. :)
Thanks for the hints.
2019-11-27 04:43 PM
Right click on the project -> Convert to C++
2019-11-27 11:47 PM
Thanks for the answer.
There is only "Convert to C", so I guess it's already a C++ project.
2019-11-28 08:41 AM
> so I guess it's already a C++ project
Yeah. Then, check in "All options" the compiler command line that it passes the correct .specs, and this .specs defines correct include path.
-- pa
2019-11-28 04:20 PM
I am not sure I understand what you are asking for. The compiler is called like this (cut from terminal):
arm-none-eabi-gcc "../Core/Src/rtc.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32F412Cx -DUSE_HAL_DRIVER -DDEBUG -c -I../Drivers/CMSIS/Include -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Core/Inc -I../App/Inc -Os -ffunction-sections -fdata-sections -Wall -Wextra -pedantic -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wconversion -fstack-usage -MMD -MP -MF"Core/Src/rtc.d" -MT"Core/Src/rtc.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/rtc.o"
Yes, that's one of the C files. I do not see any calls for arm-none-eabi-g++ since the first C++ file already fails.
In file included from ../App/Inc/can_bus.hpp:4:0,
from ../Core/Src/main.c:22:
../App/Inc/cluster_data.hpp:7:10: fatal error: cstdint: No such file or directory
#include <cstdint>
^~~~~~~~~
compilation terminated.
Note that there are no lines between those two snippets in the terminal.
2019-11-28 09:55 PM
Your file main.c is a C file (as it should be, because Cube generates C files) therefore it is correctly compiled with gcc (not g++).
C files cannot include cstdint, this is a c++ specific include file.
Add some c++ file to your project, for example test.cpp. See if this will compile with g++.
-- pa
2019-11-28 11:59 PM
Oh, you are right about the main.c. The cluster_data.hpp is supposed to be a C++ header file but if included in a C file it is compiled in that file's context. ... If CubeMX can only generate C files and I need to call my application logic from main.c, how can I then start a C++ project?
2019-11-29 10:25 AM
I renamed main.c to main.cpp and it compiled. Sure there will be some fine-tuning to do but it's one step forward. :)
Thanks for the hints.