ESP-IDF 5自制组件找不到driver/gpio.h

问题描述 投票:0回答:1

我使用 ESP-IDF 框架在 VSCode 中使用 PlatformIO 从头开始创建了一个新项目。

我有这个结构

/
|-components
| |-include
| |-src
|
|-include
|
|-lib
|
|-src
|
|-test

在 src 文件夹中存在主文件。 如果在该主文件中包含“driver/gpio.h” 它工作正常,我可以访问 GPIO。

现在,当我将代码移动到组件文件夹中的组件时,编译器显然找不到“driver/gpio.h”

In file included from components\mypirComponent\src\mypirComponent.cpp:1:
components\mypirComponent\include/mypirComponent.hpp:9:10: fatal error: driver/gpio.h: No such file or directory
    9 | #include "driver/gpio.h"
      |   

我似乎没有在 platformio / ESP-IDF 工具链中找到导致此问题的原因。 我应该怎么做才能解决这个问题?

visual-studio-code esp32 platformio esp-idf
1个回答
0
投票

包含在 CMakeLists.txt 文件中。 IDF 不会自动添加它。我不知道技术原因,但这解决了我的问题。

idf_component_register(SRCS ${SOURCE_FILES}
                       REQUIRES drivers
                       INCLUDE_DIRS "src")
© www.soinside.com 2019 - 2024. All rights reserved.