In included file 'avr/pgmspace.h' file not found

Hello there!
I’m on Linux, using vim and I use clangd as my language server. The code compiles fine but it always gives me something missing, e.g. Use of undeclared identifyer ‘Serial’ and In included file ‘avr/pgmspace.h’ file not found, among others.
Because of these errors a lot of language server functions dont work.

Thank you!

What does your .ccls file look like in the project directory?

clang

%c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p
%cpp -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p

-I/home/lydia/Software/Workspaces/electronics/ldr/include
-I/home/lydia/Software/Workspaces/electronics/ldr/src
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/cores/arduino
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/variants/standard
-I/home/lydia/.local/share/platformio/packages
-I/home/lydia/.local/share/platformio/platforms
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/libraries/EEPROM/src
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/libraries/HID/src
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/libraries/SPI/src
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src
-I/home/lydia/.local/share/platformio/packages/framework-arduino-avr/libraries/Wire/src
-I/home/lydia/.local/share/platformio/packages/toolchain-atmelavr/lib/gcc/avr/7.3.0/include-fixed
-I/home/lydia/.local/share/platformio/packages/toolchain-atmelavr/lib/gcc/avr/7.3.0/include
-I/home/lydia/.local/share/platformio/packages/toolchain-atmelavr/avr/include

-DPLATFORMIO=50101
-DARDUINO_AVR_UNO
-DF_CPU=16000000L
-DARDUINO_ARCH_AVR
-DARDUINO=10808
-D__AVR_ATmega328P__

It really depends on what I use as language server. if I use ccls then the include file error is gone (because of .ccls) but it still does not recognize Serial or digital, among other core functions

If i use clangd same error, along with the error I mentioned in my previous comment

PS: I have modified the env variables to best suit my workflow, I still get the same error even if all pio variables are reset to default

Please open an issue in Issues · platformio/platformio-core · GitHub for that with the exact software / components tha you’re using there. Vim support was previously corrected per this issue but if you say both is broken, it might be in need of another update. All I see is that

is correctly in the include paths where Arduino.h is, which includes all other headers for Serial and digitalWrite() etc. So if your code has a #include <Arduino.h> at the top and it still can’t find the functions, that’s a bug.

it does have the Arduino include. with ccls I get no error on the line #include but I get it everywhere else. with clangd I get the error even on the #include line usually refering to a missing stdlib.h (huh!!!) or some other Atmel header

i could open an issue on git. but did not want to go that route if it was fixable through a forum discussion ad/or it was because i personally overlooked something simple

Everywhere else meaning, in different .cpp files of the projects, or where? What’s the exact platformio.ini and code here? Screenshot of the error?

everywhere else where Serial and such are mentioned.

Screenshot and the rest coming…


in this example there is only error on Serial, others are fine. Let me find you an example with other errors as well

[env:uno]
platform = atmelavr
board = uno
framework = arduino

Well in that folder there should be the file avr/pgmspace.h that it can’t find, although the folder is declared to it in the .ccls file.

This doesn’t look like a error on the user side. This example is so simple and clear that it shouldn’t fail. It failing indiciates that either PlatformIO generates the .ccls file wrongly or something else has a bug. Please open an issue per link above with your project information (platformio.ini + code), error screenshot, and used vim / plugins versions.

I may be late, but just for future users, I solved in this way (I am using clangd). Add the following line to your platformio.ini file for creating the compile_commands.json file:

build_flags = --target=avr

then, remove it, otherwise your actual project won’t build.