目前为止在csdn中看到的几个方法全部都是错误的,基本是修改c_cpp_properties.json
但是其实这个文件你只要一打开就能看到上面的警告标识
//
// !!! WARNING !!! AUTO-GENERATED FILE!
// PLEASE DO NOT MODIFY IT AND USE "platformio.ini":
// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
//
如果你装了vscode的更好的注释插件,两个感叹号将会启用红色高亮
提示你这个文件是自动生成的,请不要修改这个文件。其实这个跟cubeMX生成的文件是类似的,他会随着你IDE启动或者是修改配置自动更新自动生成。在这里修改的内容你只要重新编译或者进行某种操作就会直接消失。
我在CSDN看到不止一个帖子是这么做的,以上做法均为错误做法。
正确的做法是将你外部库的.c和.h分别放置到pio工程目录的src和include中
修改完成后IDE会自动将路径添加到json文件中,不需要手动修改这个文件,况且手动修改也是无效的
{
"configurations": [
{
"name": "PlatformIO",
"includePath": [
"c:/Users/TerayTech/Documents/PlatformIO/Projects/auto_range_voltimeter/include",
"c:/Users/TerayTech/Documents/PlatformIO/Projects/auto_range_voltimeter/src",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/cores/arduino",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/variants/mega",
"c:/Users/TerayTech/Documents/PlatformIO/Projects/auto_range_voltimeter/.pio/libdeps/megaatmega2560/AD7606",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/libraries/HID/src",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
"C:/Users/TerayTech/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
""
],
修改后编译轻松通过
Checking size .pio\build\megaatmega2560\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 2.2% (used 184 bytes from 8192 bytes)
Flash: [ ] 0.9% (used 2162 bytes from 253952 bytes)
Building .pio\build\megaatmega2560\firmware.hex