Libraries ok for arduino but error for idf platform

I have created 2 simple projects from sratch, both with the same platform and board, but different framework (android and espidf)
Using the librarie manager I installed the “PubSubClient” to both projects, and changed the “platformio.ini” file.
The “android” project builds ok, but the “espidf” project fails with the following message:

Compiling .pio\build\esp32dev\esp-idf\src\main.c.o
src\main.c:1:10: fatal error: PubSubClient.h: No such file or directory

* Looking for PubSubClient.h dependency? Check our library registry!
* CLI  > platformio lib search "header:PubSubClient.h"
* Web  >

 #include <PubSubClient.h>
compilation terminated.
Compiling .pio\build\esp32dev\esp-idf\app_trace\app_trace_util.c.o
Compiling .pio\build\esp32dev\esp-idf\app_trace\host_file_io.c.o
*** [.pio\build\esp32dev\esp-idf\src\main.c.o] Error 1
Compiling .pio\build\esp32dev\esp-idf\app_trace\gcov\gcov_rtio.c.o

The platformio.ini file looks as follows:

platform = espressif32
board = esp32dev
framework = espidf
lib_deps =
  # Using a library name

and the source code as follows:

#include <PubSubClient.h>
void app_main() {}

Does anyone have an idea how I can solve the problem with the espidf project?

I tried this with the latest version of vscode and platformio and on two different windows systems. Both have the same behaviour

This library (PlatformIO Registry) is targeted at the Arduino framework so it won’t work when you just specify framework = espidf since the Arduino core APIs and libraries are not available.

I suggest to use the native MQTT client of ESP-IDF (example e.g. here).

Alternatively the Arduino-core can be enabled as an ESP-IDF component to slap Arduino on top of ESP-IDF. This is shown in an example.

1 Like

I’m sure you meant Arduino here instead of “Android”?

1 Like

Hi @maxgerhardt, that makes sense. I will give it a try. Thanks for the quick response.

1 Like