【问题标题】:How to add an ESP-IDF library to an external library如何将 ESP-IDF 库添加到外部库
【发布时间】:2021-12-02 08:32:55
【问题描述】:

我正在尝试将外部库添加到我的项目中。

我的项目结构如下:

-project
   -- main
     --- main.c
     --- displayfunctions.c (where i implement my Displayfunctions based on the library)
     --- 2 other .c files which got nothing to do with my Display
     --- CMakeLists.txt 
   -- components
     --- displaylibrary
       ---- CMAKELists.txt
       ---- all displayrelevant librarys pngle.c fontx.c etc..
       ---- include
          ----- all corresponding header files pngle.h fontx.h etc.

我在 project/components/displaylibrarys 中的 CMakeLists.txt 文件如下所示:

idf_component_register(SRCS "pngle.c" "decode_jpeg.c" "decode_png.c" "fontx.c" "ili9340.c"
                       INCLUDE_DIRS "include" )


include($ENV{IDF_PATH}/tools/cmake/project.cmake)

当我尝试编译我的项目时,我收到以下错误消息:

../components/Displaylibrarys/fontx.c:7:10: fatal error: esp_spiffs.h: No such file or directory #include "esp_spiffs.h"

所以显然我的编译器没有将我的外部库中包含的 esp-idf 库与实际的 esp-idf 库链接。我也尝试过这种方法

idf_component_register(SRCS "pngle.c" "decode_jpeg.c" "decode_png.c" "fontx.c" "ili9340.c"
                       INCLUDE_DIRS "include"
                       REQUIRES esp_spiffs)

但没有结果。我应该如何正确地告诉我的编译器它知道这个库?

【问题讨论】:

  • REQUIRES 子句看起来不错,只是组件被称为“spiffs”而不是“esp_spiffs”。
  • 哇哦。那完成了工作......我挣扎了2天。非常感谢!!!
  • 你为什么转发同样的问题而不是跟进原来的问题? stackoverflow.com/questions/70186133/…

标签: visual-studio-code esp32 directory-structure esp-idf cmakelists-options


【解决方案1】:

ESP-IDF 构建系统使用组件。您的库是一个组件,ESP-IDF 库的许多部分也是如此。

作为组件方法的一部分,您的组件需要声明它依赖的其他组件。这就是REQUIRES 子句的用途。

除了组件被称为 spiffs 而不是 esp_spiffs 之外,您几乎是正确的。

idf_component_register(SRCS "pngle.c" "decode_jpeg.c" "decode_png.c" "fontx.c" "ili9340.c"
                       INCLUDE_DIRS "include"
                       REQUIRES spiffs)

我通常检查 ESP-IDF 组件目录以找出正确的名称。组件和目录名相同:https://github.com/espressif/esp-idf/tree/master/components

【讨论】:

    猜你喜欢
    • 2022-06-11
    • 2023-02-17
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 2022-06-19
    • 2019-03-27
    • 1970-01-01
    • 2022-11-12
    相关资源
    最近更新 更多