Page 1 of 1

ESP-IDF create custom library

Posted: Tue Aug 21, 2018 6:50 am
by Adham Aboud
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

Re: ESP-IDF create custom library

Posted: Tue Aug 21, 2018 7:41 pm
by kolban
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.

Re: ESP-IDF create custom library

Posted: Thu Aug 23, 2018 7:04 am
by Adham Aboud
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

Re: ESP-IDF create custom library

Posted: Thu Aug 23, 2018 7:26 pm
by kolban
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.

Re: ESP-IDF create custom library

Posted: Fri Aug 24, 2018 6:58 am
by Adham Aboud
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,

Re: ESP-IDF create custom library

Posted: Thu Nov 12, 2020 11:40 am
by bloobird0
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?