Search code examples
visual-studio-codeesp32esp-idf

esp-idf build fails with "fatal error: esp_wifi.h: No such file or directory"


I am a student who has gotten a part time job embedded system programming. I am given a program the company uses, and asked to understand it. This is a working program. Therefore, the project can be built and flashed on ESP32 by the developers with no problem. So, the code and CMake files should have no issues. However, I cannot build the program either with VSCode extension nor with idf.py. In fact, I cannot build esp-idf examples from the official website, either. Note: I am new to StackOverflow as well as to ESP32, so sorry if I made any mistakes here. If this post is problematic in any way, please inform me. The error message from the terminal is shown here

I was initially using VSCode on Windows 10 (Windows is not activated). At first, ESP extension was completely failing to start the building process because it could not locate the tools. I was getting "could not be located" errors for all the tools. Below is a list of what I did in this setting:

  1. I had v5.0.0 for esp-idf downloaded from Espressif server. I deleted it and tried v4.3.3 and then I tried to download from Github server. I downloaded the requirements for idf.py scripting environment and completed the settings for it as described by the Espressif's documentation.
  2. I manually set the environment variables for IDF_PATH and PATH for both the user and for the system. After 2, the initial error was gone. Unfortunately, I had a new error which indicated that ".elf" file for the project output could not be found. I do not exactly recall the error but if it is integral to the problem's solution I can try to replicate this issue.
  3. I tried to delete and reinstall VSCode. I tried running VSCode with admin authority.
  4. I tried changing the IDF_TOOLS_PATH in the VSCode esp-idf extension configurations from ".espressif" to "esp\esp-idf".

At this point, I moved to try to build the project on Ubuntu 22.04.1 LTS:

  1. In Ubuntu, I got the fatal error: esp_event.h: No such file or directory error. It does not seem to be a common issue and I could not find much about it online. I followed the Linux setup steps in the documentation. It said that only step 1 (Downloading the prerequisites) was necessary for the VSCode extension.
  2. I decided to try the "master branch" from esp-idf configurations as well. After I downloaded the master branch, the error changed to the current version: 'fatal error: esp_wifi.h: No such file or directory'
  3. I also tried the idf.py in Ubuntu but I got the same error.

Both in Ubuntu and in Windows, the Doctor Command returns nothing. It does not even open the terminal or any window. I am not sure what it should return but some online discussions were asking about its return so I wanted to note it here.


Edit: When I tried the examples on Ubuntu, they actually build just fine. Doctor Command also works with examples. However, the main code has still issues. Initially, I assumed I made some mistakes with esp-idf configurations. But, perhaps that was not the case.


Solution

  • I had the same problem and ended up editing my project's CMakeLists.txt. When I added "esp_wifi" to the "REQUIRES" list, it worked for me:

    idf_component_register(
        SRCS "main.c"
        INCLUDE_DIRS res
        EMBED_FILES res/settings.html
        REQUIRES esp_wifi
    )