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
ESP-IDF create custom library
Re: ESP-IDF create custom library
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.
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
-
- Posts: 48
- Joined: Mon Apr 30, 2018 5:32 pm
Re: ESP-IDF create custom library
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
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
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.
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
-
- Posts: 48
- Joined: Mon Apr 30, 2018 5:32 pm
Re: ESP-IDF create custom library
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,
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
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?
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: No registered users and 313 guests