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

问题

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

esp_adc_error_log.txt
/home/user/MyProject/main/main.cpp:3:10: fatal error: esp_adc/adc_oneshot.h: No such file or directory
    3 | #include <esp_adc/adc_oneshot.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

解决方案

你需要确保项目中包含 esp_adc 组件。这可以通过修改 main/CMakeLists.txt 文件将 esp_adc 组件添加为依赖项来实现。

你可以在 idf_component_register 函数中添加 REQUIRES esp_adc 行。以下是修改 main/CMakeLists.txt 文件的方法:

idf_component_register_esp_adc.cmake
idf_component_register(
    SRCS "main.cpp"
    INCLUDE_DIRS "../include"
    REQUIRES esp_adc
)

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