ESP32:如何修复 ESP-IDF 致命错误:esp_timer.h: No such file or directory

问题

编译 ESP-IDF 项目时,你可能会遇到以下错误:

esp_timer_error_log.txt
/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.

解决方案

要解决此问题,你需要确保项目中包含 esp_timer 组件。这可以通过修改 main 目录中的 CMakeLists.txt 文件将 esp_timer 组件添加为依赖项来实现:

idf_component_register_esp_timer.cmake
# ...
idf_component_register(
  # ...
  REQUIRES esp_timer
)

如果已有 REQUIRES 行,只需将 esp_timer 添加到所需组件列表中(以空格分隔)。


Check out similar posts by category: ESP32, ESP-IDF