How to fix ESP-IDF fatal error: esp_timer.h: No such file or directory

Problem

When compiling an ESP-IDF project, you might encounter the following error:

/home/uli/myproject/main/src/ADC.cpp:17:10: fatal error: esp_timer.h: No such file or directory
   17 | #include <esp_timer.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

Solution

To resolve this issue, you need to ensure that the esp_timer component is included in your project. This can be done by modifying your CMakeLists.txt file in the main directory to include the esp_timer component as a requirement:

# ...
idf_component_register(
    # ...
    REQUIRES esp_timer
)

In case there is a REQUIRES line already, simply add esp_timer to the list of required components (separated by spaces).