ESP32:如何修复 ESP-IDF 致命错误:cJSON.h: No such file or directory
问题
构建 ESP-IDF 项目时,你可能会遇到以下错误:
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.解决方案
你需要确保项目中包含 json 组件。这可以通过修改 main/CMakeLists.txt 文件将 json 组件添加为依赖项来实现。
你可以在 idf_component_register 函数中添加 REQUIRES json 行。以下是修改 main/CMakeLists.txt 文件的方法:
idf_component_register_json.cmake
idf_component_register(
SRCS "main.cpp"
INCLUDE_DIRS "..\include"
REQUIRES json
)If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow