How do examples work without specifying their component requirements?

MoAtef
Posts: 2
Joined: Sun Mar 23, 2025 2:35 pm

How do examples work without specifying their component requirements?

Postby MoAtef » Sun Mar 23, 2025 3:01 pm

Code: Untitled.cmake Select all

Hello, Espressif community,

I have recently started learning ESP32 development using ESP-IDF. It is usually recommended to see how things are done in examples and then apply them to your project. I was trying to get started using Wi-Fi on my ESP32.

In a project I created I have to use the PRIV_REQUIRES ESP-IDF CMake directive to indicate which components my main component depends on or it won't build. I had to add esp_wifi (which makes sense), but I also had to add nvs_flash (which doesn't make sense to me as it should have been included automatically since it is a dependency of esp_wifi). On the other hand, this example Wi-Fi project https://github.com/espressif/esp-idf/tr ... /fast_scan doesn't have any components required, and it builds without any issues (I have tried it on the same PC!).

So what am I missing here? Both projects have only a single source file. Here are the main component CMakeLists files for both:

My project (created from the sample_project template):

Code: Select all

idf_component_register(SRCS "main.c"
                    PRIV_REQUIRES esp_wifi nvs_flash
                    INCLUDE_DIRS ".")
The example fast_scan project:

Code: Select all

idf_component_register(SRCS "fast_scan.c"
                    INCLUDE_DIRS ".")
There must be something very obvious I am missing here, but I am following the documentation and the ESP32-C3 Wireless Adventure book and I can't find an explanation so far.

Thank you.

Sprite
Espressif staff
Espressif staff
Posts: 10651
Joined: Thu Nov 26, 2015 4:08 am

Re: How do examples work without specifying their component requirements?

Postby Sprite » Mon Mar 24, 2025 12:29 am

Unless you set PRIV_REQUIRES/REQUIRES, the 'main' component automagically requires all available components.

MoAtef
Posts: 2
Joined: Sun Mar 23, 2025 2:35 pm

Re: How do examples work without specifying their component requirements?

Postby MoAtef » Mon Mar 24, 2025 12:38 am

Ok, this makes sense now.

Thanks for the help!

Who is online

Users browsing this forum: ChatGPT-User and 2 guests