Cómo solucionar el error fatal de ESP-IDF: cJSON.h: No such file or directory

Problema

Al compilar un proyecto ESP-IDF, puedes encontrar el siguiente error:

cjson_fatal_error.txt
/home/user/MyProject/main/main.cpp:10:10: fatal error: cJSON.h: No such file or directory
   10 | #include <cJSON.h>
      |          ^~~~~~~~~
compilation terminated.

Solución

Necesitas asegurarte de que el componente json esté incluido en tu proyecto. Esto se puede hacer modificando tu archivo main/CMakeLists.txt para incluir el componente json como dependencia.

You can do this by adding the REQUIRES json line in your idf_component_register function. Here’s how to modify your main/CMakeLists.txt file:

idf_component_register_json.cmake
idf_component_register(
  SRCS "main.cpp"
  INCLUDE_DIRS "..\include"
  REQUIRES json
)

Echa un vistazo a artículos similares por categoría: ESP-IDF, ESP32