Pico `build_flags = -I pgmspace.h` Doesn't affect build - "pgmspace.h: No such file or directory"


I was trying to use the Adafruit_SSD1306 library in a Pico project but it gets the following error (full build output below):

.pio\libdeps\pico\Adafruit SSD1306\Adafruit_SSD1306.cpp:42:10: fatal error: pgmspace.h: No such file or directory

Apparently this is not needed for 32-bit devices and can be commented out but I’m trying to avoid modifying the library and I don’t get this error for the pico using the Arduino IDE.

I have found a compatible header here: ArduinoCore-sam/pgmspace.h at master · arduino/ArduinoCore-sam · GitHub

And added it to the include folder include/pgmspace.h and added it to build_flags in platformio.ini as follows:

platform = raspberrypi
board = pico
framework = arduino
lib_deps = 
	adafruit/Adafruit SSD1306@^2.5.4
build_flags = -I pgmspace.h

However this line doesn’t seem to affect the output, I still get the same error / missing file:
build_flags = -I pgmspace.h

I have tried to make the build log more verbose, but I’m not seeing anything in the output that confirms it’s loaded this included header.

Is it supposed to work this way (e.g. loading a header so a library can use it)?
I’m new to platform io - this project works in the arduino IDE with the rp2040 board.

Build output:

> Executing task in folder fstq-pro-proto1: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe run <

Processing pico (platform: raspberrypi; board: pico; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html
PLATFORM: Raspberry Pi RP2040 (1.7.0) > Raspberry Pi Pico
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd)     
 - framework-arduino-mbed @ 3.1.1
 - tool-rp2040tools @ 1.0.2
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 42 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit SSD1306 @ 2.5.4
|   |-- Adafruit GFX Library @ 1.11.2
|   |   |-- Adafruit BusIO @ 1.11.6
|   |   |   |-- Wire
|   |   |   |-- SPI
|   |   |-- Wire
|   |   |-- SPI
|   |-- Adafruit BusIO @ 1.11.6
|   |   |-- Wire
|   |   |-- SPI
|   |-- Wire
|   |-- SPI
|-- SerialCommands @ 2.2.0
|-- Adafruit GFX Library @ 1.11.2
|   |-- Adafruit BusIO @ 1.11.6
|   |   |-- Wire
|   |   |-- SPI
|   |-- Wire
|   |-- SPI
|-- Fd_tm1638
|-- SPI
|-- Wire
Building in release mode
Compiling .pio\build\pico\src\fsmp_throttle_pro_io.cpp.o
Generating LD script .pio\build\pico\cpp.linker_script.ld
Compiling .pio\build\pico\libf28\Wire\Wire.cpp.o
Compiling .pio\build\pico\lib4b9\SPI\SPI.cpp.o
Compiling .pio\build\pico\lib512\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o
Compiling .pio\build\pico\lib512\Adafruit BusIO\Adafruit_I2CDevice.cpp.o
Compiling .pio\build\pico\lib512\Adafruit BusIO\Adafruit_SPIDevice.cpp.o
Compiling .pio\build\pico\lib4c3\Adafruit GFX Library\Adafruit_GFX.cpp.o
Compiling .pio\build\pico\lib4c3\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o
Compiling .pio\build\pico\lib4c3\Adafruit GFX Library\Adafruit_SPITFT.cpp.o
Archiving .pio\build\pico\lib4b9\libSPI.a
Archiving .pio\build\pico\libf28\libWire.a
Compiling .pio\build\pico\lib4c3\Adafruit GFX Library\glcdfont.c.o
Compiling .pio\build\pico\libfcb\Adafruit SSD1306\Adafruit_SSD1306.cpp.o
Compiling .pio\build\pico\lib53a\SerialCommands\SerialCommands.cpp.o
Compiling .pio\build\pico\liba1d\Fd_tm1638\Fd_tm1638.cpp.o
Compiling .pio\build\pico\liba1d\Fd_tm1638\Fd_tm16xx.cpp.o
.pio\libdeps\pico\Adafruit SSD1306\Adafruit_SSD1306.cpp:42:10: fatal error: pgmspace.h: No such file or directory

* Looking for pgmspace.h dependency? Check our library registry!
* CLI  > platformio lib search "header:pgmspace.h"
* Web  > https://registry.platformio.org/search?q=header:pgmspace.h

   42 | #include <pgmspace.h>
      |          ^~~~~~~~~~~~
compilation terminated.
Archiving .pio\build\pico\lib512\libAdafruit BusIO.a
*** [.pio\build\pico\libfcb\Adafruit SSD1306\Adafruit_SSD1306.cpp.o] Error 1

-I adds a path to a folder to the include search space. pgmspace.h is likely not a valid folder (which is seen relative to the project folder).

Since you put the file in include, do -Iinclude/ instead.


That worked, Thank you very much!

Oh that makes much more sense in hindsight too :see_no_evil:

Thank you very much for this solution of the problem which got me stucked few months ago (for a project on arduino nano RP2040).
Soution summary (to make things clear, since it was not easy for me to understand all the explanation above) :

  1. added the “pgmspace.h” from the link in the “include” folder
  2. added the line below to platformio.ini:
    build_flags = -Iinclude/

Although, this solution (and the origin of the problem) looks very mysterious for me…
If you have time to shortly explain the origin of the error and what the solution does… I would be more than grateful !
Thanks again.

See Program Space Utilities (pgmspace.h) · Issue #343 · arduino/ArduinoCore-mbed · GitHub.