How to fix ESP-IDF fatal error: esp_wifi.h: No such file or directory
Problem
When building an ESP-IDF project, you may encounter the following error:
main.cpp
/home/user/MyProject/main/main.cpp:2:10: fatal error: esp_wifi.h: No such file or directory
2 | #include <esp_wifi.h>
| ^~~~~~~~~~~~
compilation terminated.
```plaintext {filename="main.cpp"}
## Solution
You need to ensure that the `esp_wifi` component is included in your project. This can be done by modifying your `main/CMakeLists.txt` file to include the `esp_wifi` component as a dependency.
You can do this by adding the `REQUIRES esp_wifi` line in your `idf_component_register` function. Here’s how to modify your `main/CMakeLists.txt` file:
```cmake {filename="idf_component_register_wifi.cmake"}
idf_component_register(
SRCS "main.cpp"
INCLUDE_DIRS "../include"
REQUIRES esp_wifi
)
```plaintext {filename="idf_component_register_wifi.cmake"}
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow