What a weird error I found

This is obviously an avr tool chain error, so I would guess switching them would be in order.

At the head of my cpp file is the following

#ifdef IS_D1
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Arduino.h>

For the Wemos D1, I have a “build_flags = -D IS_D1” in the env entry in the platformio.ini. Compiles work as expected. As a test, I force an error in the line "#include lalala <Arduino.h>" and compiles without error.

When I compile for the uno (IS_D1 not defined), I go down the rabbit hole with an error that shouldn’t happen.

Archiving .pioenvs\uno\libFrameworkArduino.a
Compiling .pioenvs\uno\lib\WiFi\utility\spi_drv.o
Compiling .pioenvs\uno\lib\WiFi\utility\wifi_drv.o
Indexing .pioenvs\uno\libFrameworkArduino.a
Archiving .pioenvs\uno\lib\libWire.a
C:\users\Peter Carter\.platformio\packages\framework-arduinoavr\libraries\WiFi\src\utility\spi_drv.cpp:21:17: fatal error: SPI.h: No such file or
#include <SPI.h>Indexing .pioenvs\uno\lib\libWire.a

compilation terminated.
*** [.pioenvs\uno\lib\WiFi\utility\spi_drv.o] Error 1

With an uno, SPI and WiFi should not even be needed. Although this is a genuine file error, it should not have been triggered with this compile. I use WIRE, but not SPI or WIFi.

If I use the following on the uno

#ifdef IS_D1
//#include <ESP8266WiFi.h>
//#include <ESP8266mDNS.h>
//#include <WiFiUdp.h>
//#include <ArduinoOTA.h>
#include <Arduino.h>

The uno compiles fine. Go figure

If I use the following on the uno…

#ifdef IS_D1
#include la la la <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Arduino.h>

It does not error out on the “la la la”, but it does suffer from the same compile error above.

So, the logic of compiles (in avr) seem to be ok, but what ever makes decisions on what else is needed to compile is flawed.

My mbed, simba and esp8266 compiles all work as expected.

Lost a few days trying to figure out what was wrong.

Some deeper digging, the WiFiUdp.h is the trigger. I can comment out just this line and compile arduino bords without error.

The library exists in both arduino and esp8266 arcs.

My official guess is the library scanner is not looking at conditionals, just include statements.

There are no issues with compiles on the Arduino IDE.

You need


Try lib_ldf_mode = chain+.

I did read that, and tried. Same results/

Could you try to ignore these libs for uno?

lib_ignore = WiFi

It does. Thanks.

I love PlatformIO. I was attracted buy the multi-build environment. This behavior does make it cumbersome to build multi-platform / multi-board projects. All you would need is to process #ifdefs / comments and it would go away.

With comments, “//” work as expected, but /* … */ (multi line) do not. So even mentioning a .h in the comments will trigger this error.

Otherwise it is a solid product. Well done!

This is a bug, we have related issue and will investigate it soon. Sorry.

As long as it is in the list, all is good.