PlatformIO Community

Fatal error: WiFiClientSecure.h: No such file or directory

I created an MQTT library and when optimizing the code, this error popped up:

fatal error: WiFiClientSecure.h: No such file or directory

I ran compilation tests using the platformio ci command for esp8266 and esp32. All examples except one are building without problems. Only on ESP32 on the example where the secure variant is not used, it fails.

See deduplicate code · bertmelis/espMqttClient@6956fd5 (

I don’t immediately see what I’ve done wrong. The example used to compile fine and the dependencies have not changed, only reshuffled between files.

I’ve got 2 header files to be included by the user of the lib: one with WiFiClient as dependency and one with WiFiClientSecure. As a test I changed the non-secure version so it includes WiFiClientSecure. This works because WiFiClientSecure includes WiFiClient, so dependencies are met.

  • original case: does not work, fails to find WiFiClientSecure
    • MqttClient includes WiFiClient → works
    • MqttClientSecure includes WiFiClientSecure → fails on non-secure example, which doesn’t use MqttClientSecure. But only on ESP32, ESP8266 compiles
  • testcase: works on all examples
    • MqttClient includes WiFiClientSecure (which includes WiFiClient)
    • MqttClientSecure includes WiFiClientSecure

As a workaround I can of course combine the two header files. But I just don’t see the reason why it fails like it is now.