PlatformIO (vscode) insists on including undefined libraries

I have a folder with my custom (and downloaded libraries) that I include them in my projects. I use lib_extra_dirs = ..\..\common
Usually, my projects compile successfully. My newest project uses ESP8266 or ESP32 based on #ifdef ESP32. For example:

#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncDNSServer.h> // <-- why this library is included when I compile for ESP32?
#elif defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#include <DNSServer.h>
#else
#error not supported platform
#endif

The above commented library is in ../../common/ESPAsyncDNSServer folder. If I compile for ESP32 it is included in compilation and of course gives errors:
Dependency graph for ESP32:

|-- <WebConfig2>
|   |-- <AsyncTCP> 1.1.1
|   |-- <ESPAsyncDNSServer>    <---- This should not be included
|   |   |-- <ESPAsyncUDP>
|   |-- <WiFi> 1.0
|   |-- <DNSServer> 1.1.0
|   |   |-- <WiFi> 1.0
|   |-- <ESPAsyncWebServer>
|   |   |-- <AsyncTCP> 1.1.1
|   |   |-- <ArduinoJson> 6.15.0
|   |   |-- <WiFi> 1.0
|   |   |-- <FS> 1.0
|   |-- <GlobalSettings>
|   |   |-- <SPIFFS> 1.0
|   |   |   |-- <FS> 1.0
|   |   |-- <ArduinoJson> 6.15.0
|   |   |-- <WiFi> 1.0
|   |   |-- <FS> 1.0
|   |-- <ArduinoJson> 6.15.0
|   |-- <Helper>
|   |   |-- <SPIFFS> 1.0
|   |   |   |-- <FS> 1.0
|   |   |-- <ArduinoJson> 6.15.0
|   |   |-- <FS> 1.0
|   |   |-- <WiFi> 1.0
|-- <GlobalSettings>
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|   |-- <ArduinoJson> 6.15.0
|   |-- <WiFi> 1.0
|   |-- <FS> 1.0

If I compile only for ESP and I comment out the line #include <ESPAsyncDNSServer.h> it compiles successfully.
platformio.ini:

[platformio]
build_dir=C:\programming\pio\build

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200
lib_extra_dirs = 
  ..\..\common

[env:esp32_cam]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_extra_dirs = 
  ..\..\common

Any help is appreciated.

I think that is related to my past question https://community.platformio.org/t/after-upgrading-to-4-2-0-my-project-that-uses-espasyncwebserver-does-not-compile/11998
If I set lib_ignore = ESPAsyncDNSServer to ESP32 env of platformio.ini it compiles successfully.
But can this be fixed or should we live with this?

Because the library dependency finder does not evaluate your #ifdef ESP8266 macro when checking the source code by default. For that, use the documented lib_ldf_mode (docs) directive, e.g. the chain+ or deep+ values.

1 Like