Linking Espressif libraries to run their demos

Hello,

I’m running my own main.c file and using amazon freertos as a external library. In my main.c I’m trying to run espressif’s spiff example.

trying to compile the first time, the compiler couldn’t find esp_spiffs.h. So, I hardcoded the location. not great, but got me past the error.

#include "../../amazon-freertos/vendors/espressif/esp-idf/components/spiffs/include/esp_spiffs.h"

Trying to compile for a second time, the esp_spiffs.c can’t find esp_spiffs.h. I’m guessing since I hardcoded the location of esp_spiffs.h in my main.c that esp_spiffs.c can’t use that.

../amazon-freertos/vendors/espressif/esp-idf/components/spiffs/esp_spiffs.c
../amazon-freertos/vendors/espressif/esp-idf/components/spiffs/esp_spiffs.c:15:10: fatal error: esp_spiffs.h: No such file or directory
 #include "esp_spiffs.h"

What do I try next?

I have read I should update my compiler with the location of the espressif components, but I haven’t found how to do that?

If I do update this location in my compiler, will this resolve this issue for when I move forward to add more of espressif’s components?

Some details if needed…
spiffs demo is located at
/amazon-freertos/vendors/espressif/esp-idf/examples/storage/spiffs/main/spiffs_example_main.c

my CMAKEList.txt

cmake_minimum_required(VERSION 3.13)

project(freertos_spiffs)

# Tell IDF build to link against this target.
set(IDF_EXECUTABLE_SRCS
        "/src/main.c"
        "/amazon-freertos/vendors/espressif/esp-idf/components/spiffs/esp_spiffs.c"
        )
set(IDF_PROJECT_EXECUTABLE hello_world_app)

# Add FreeRTOS as a subdirectory. AFR_BOARD tells which board to target.
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL "")
add_subdirectory(amazon-freertos)

# Link against the mqtt library so that we can use it. Dependencies
# are transitively linked.
target_link_libraries(
        hello_world_app
        PRIVATE
        AFR::core_mqtt
        )

Hi @DoubleH,

You can add directories to your build’s include path with CMake’s target_include_directories.

What I observe from your CMakeLists.txt is that you’re mostly setting variables related to AFR and ESP-IDF, and it looks like you’re relying on the cmake configuration in amazon-freertos to build the project from those variables. For your current configuration, I suspect there may be an IDF variable related to the include path that you have to set to add more directories to it.

When I’ve used cmake before for my own sources, I’ve generally set the sources for the target with add_executable, the include path with target_include_directories, and any libraries with target_link_libraries. Perhaps if you are still having difficulty with your current cmake configuration, then you can consider a similar approach and gather your source files and include directories in one cmake file, while linking AFR as a library.

Hi @DoubleH,

It is not recommended to add individual sources/headers from IDF components. Instead you can link IDF component target to the example target.

If you want to use SPIFFS component in example, you can update target_link_libraries to:

target_link_libraries(
        hello_world_app
        PRIVATE
        AFR::core_mqtt
        idf::spiffs
        )

Hope this helps!

Thank you so much for the help @MuneebAWS and @shubhamkulkarni97 I was able to get this working.

For those looking to do the same. I had to change two files. first the esp32/CMakeLists.txt file at around line 125. I added the spiffs include files for the kernal to find. Second the idf::spiffs in my CMakeLists.txt shown above.

@shubhamkulkarni97 When I want to add other components in the future, what do I put in the spiffs part of idf::spiffs? Is this based off what folder name it’s in or something else?

Hi @DoubleH,

Ideally the change that you mentioned in esp32/CMakeLists.txt should not be required.

Regarding your question of adding other components, you should add idf::component_name in target_link_libraries. It is same as the folder name of the component.