How to fix ESP-IDF component error: #include <driver/...>: No such file or directory
Problem
When compiling your ESP-IDF project, which contains a custom component, you may encounter the following error:
QuickI2C.cpp
In file included from /home/uli/myproject/components/QuickI2C/QuickI2C/src/QuickI2C.cpp:1:
/home/uli/myproject/components/QuickI2C/QuickI2C/include/QuickI2C.h:21:10: fatal error: driver/i2c.h: No such file or directory
21 | #include <driver/i2c.h>
| ^~~~~~~~~~~~~~
compilation terminated.Solution
Edit the CMakeLists.txt file of your custom component and add the following statement inside idf_component_register:
component_CMakeLists_snippet.cmake
REQUIRES driverExample CMakeLists.txt
CMakeLists.txt
idf_component_register(SRCS "QuickI2C/src/QuickI2C.cpp"
INCLUDE_DIRS "QuickI2C/include"
REQUIRES driver)If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow