我在将字符串方法包含到C++头文件时遇到了问题。我按照这个示例创建了.cpp文件.同时,我勾选了C++选项来生成项目。 当我在app.cpp文件中使用#include <string>时,可以创建一个字符串;但我想在app.hpp文件中包含这个库时却会报错。因此无法在头文件中声明函数原型。 我使用的是Nucleo-L152re开发板。代码和错误信息如下。 //Error 1 / 21:41:30 **** Incremental Build of configuration Debug for project skytrap ****make -j8 all arm-none-eabi-g++ "../Core/Src/app.cpp" -mcpu=cortex-m3 -std=gnu++14 -g3 -DUSE_HAL_DRIVER -DSTM32L152xE -DDEBUG -c -I../Core/Inc -I../Drivers/STM32L1xx_HAL_Driver/Inc -I../Drivers/STM32L1xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-use-cxa-atexit -Wall -fstack-usage -MMD -MP -MF"Core/Src/app.d" -MT"Core/Src/app.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/app.o"arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32L152xE -DDEBUG -c -I../Core/Inc -I../Drivers/STM32L1xx_HAL_Driver/Inc -I../Drivers/STM32L1xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o"In file included from ../Core/Src/main.c:21:0:../Core/Inc/app.hpp:8:10: fatal error: string: No such file or directory #include <string> // <- Error 1 ^~~~~~~~compilation terminated.make: *** [Core/Src/subdir.mk:53: Core/Src/main.o] Error 1make: *** Waiting for unfinished jobs...."make -j8 all" terminated with exit code 2. Build might be incomplete. 21:41:32 Build Failed. 3 errors, 0 warnings. (took 2s.410ms)
|