ESP-IDF create custom library

Adham Aboud
Posts: 48
Joined: Mon Apr 30, 2018 5:32 pm

ESP-IDF create custom library

Postby Adham Aboud » Tue Aug 21, 2018 6:50 am

Hello all,

I've an esp-idf based C file and I want to build it as a custom library so I can use it in different projects.

Could you please tell me how do I make a library from C file using eclipse.


Thank you in advance

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP-IDF create custom library

Postby kolban » Tue Aug 21, 2018 7:41 pm

The model of builds for ESP-IDF applications is that one doesn't build archive files (.a files) but instead provides the source of the library in what ESP-IDF calls a "component". When we build an app using ESP-IDF, all the components are built but they are only linked in if referenced.

See for example:

https://esp-idf.readthedocs.io/en/lates ... ystem.html#

Using this you can create your own components. Should a new project wish to use that component, it would be added as a directory to your new project under that project's components folder.

Another reason for this is that the sdkconfig file controls the nature of an "app" ... the ESP-IDF uses sdkconfig at compilation time. If you built a binary library, you would be supplying an sdkconfig at build time for that library. That may not be consistent with the sdkconfig that you are going to use when you build your own app.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Adham Aboud
Posts: 48
Joined: Mon Apr 30, 2018 5:32 pm

Re: ESP-IDF create custom library

Postby Adham Aboud » Thu Aug 23, 2018 7:04 am

Thank you mr. Kolban for your answer,

I added a new folder into my root project root folder called "components" . the project tree looks like:
- myProject/
- Makefile
- sdkconfig
- components/ - component1/ - component.mk
- src1.c
- include/ - header1.h
- main/ - src1.c
- src2.c
- component.mk

- build/

When I include header1 to main/src1.c the compiler return "unresolved inclusion error". Please advice

Thank you

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP-IDF create custom library

Postby kolban » Thu Aug 23, 2018 7:26 pm

Howdy my friend,
Good post, great that you described your structure. I am thinking that "header1.h" is the declaration of the component functions. I think (from memory) that the header files for a component should live in the same directory as your component. For example, in your story,

components/component1/header1.h

if that doesn't work, try:

components/component1/include/header1.h

Please post back with what you find.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Adham Aboud
Posts: 48
Joined: Mon Apr 30, 2018 5:32 pm

Re: ESP-IDF create custom library

Postby Adham Aboud » Fri Aug 24, 2018 6:58 am

Hi Mr Kolban,

What I found is that there are two ways to solve the unresolved inclusion:
1. As you suggested before that "the header files for a component should live in the same directory as your component"
2. Add the following declaration at the *.mk file of the component in my case : COMPONENT_ADD_INCLUDEDIRS := include

Regards,

bloobird0
Posts: 2
Joined: Fri Oct 30, 2020 3:35 pm

Re: ESP-IDF create custom library

Postby bloobird0 » Thu Nov 12, 2020 11:40 am

hello,

I found this post very interesting and learned a lot of things. I react about here with my own need for a custom library.

We are in a situation that we developed a "software stack" that we can not provide our customer with its source code (licencing problem). We wanted to build a static library and make it available as a component for customer who would need to design an App out of it.

Our problem is that the current "stack" uses many modules from the IDF. Creating a static library would require to include the dependency modules in this library which is not what we want. Do you see a way to create a library without the external dependencies?

Who is online

Users browsing this forum: esp32New956832 and 101 guests