Hi!
I have a library, MQTTRemote, that depends on WiFi.h
for ESP32
and ESP8266WiFi.h
for ESP8266
.
If I add a dependency on this library and compile the project, the compilation is successful.
platformio.ini
[env:d1_mini]
platform = espressif8266@4.0.1
board = d1_mini
framework = arduino
lib_deps =
Johboh/MQTTRemote@^1.0.4
main.cpp
#include <Arduino.h>
// If <MQTTRemote.h> is included, the project compiles successfully.
// If <MQTTRemote.h> is not included, compilation failure in MQTTRemote.h on missing ESP8266WiFi.h
#include <MQTTRemote.h>
void setup() { Serial.begin(115200); }
void loop() {}
However, if don’t include the library header file, <MQTTRemote.h>
in main.cpp
, then the project doesn’t compile with a compilation error in the library itself:
In file included from .pio\libdeps\d1_mini\MQTTRemote\src\MQTTRemote.cpp:1:
.pio\libdeps\d1_mini\MQTTRemote\src\MQTTRemote.h:12:10: fatal error: ESP8266WiFi.h: No such file or directory
How come the library fail to compile when the header file is not included, but compiles as soon as it is?
I experience the same when compiling for ESP32 (but then on missing WiFi.h
).
Yes, if I’m not using the library I don’t need to depend on it, but at this point I’m trying to understand what is wrong and if there is anything I can do to still depend on the library but (not yet) using it, or if the library itself is wrong.
Regards,
Johan