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