Home > database >  How to add an ESP-IDF library to an external library
How to add an ESP-IDF library to an external library

Time:12-02

I'm trying to add an external library into my project.

My projectstructure looks like this:

-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.

my CMakeLists.txt file in project/components/displaylibrarys looks like this:

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)

when i try to compile my project I get the following Error Message:

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

so apparantly my compiler does not link the in my external library included esp-idf library with an actual esp-idf library. I tried it with this approach too

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

but without a result. How should i properly tell my compiler that it knows this library?

CodePudding user response:

The ESP-IDF build system works with components. Your library is a component, and so are many parts of the ESP-IDF library.

As part of the component approach, your component needs to declare what other components it depends on. That's what the REQUIRES clause is for.

You almost got it right except the the component is called spiffs instead of esp_spiffs.

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

I usually check the ESP-IDF components directory to figure out the correct name. The component and directory name are the same: https://github.com/espressif/esp-idf/tree/master/components

  • Related