Custom component library

leonardo
Posts: 2
Joined: Sat Feb 29, 2020 6:18 pm

Custom component library

Postby leonardo » Tue Mar 03, 2020 1:54 pm

Hi all,
I'm trying to be familiar with ESP32. I'm following the program guide and I read the build system guide but I'm not able to understand how I can create a reusable components library between more than one project and I need some help....
I try to explain better what I did:
I created an easy project with main.c and I created under a completely different directory a commoncomponents folder.
Inside commoncomponents I created mycomponent where I put mycomponent.c and mycomponent.h. I also add CMakeLists.txt containing

Code: Select all

idf_component_register(SRCS "mycomponent.c"
                       INCLUDE_DIRS ".")
In the CMakeLists.txt file of my project I set those lines:

Code: Select all

cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS "D:/commoncomponents/mycomponent")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(app-template)
And in main.c I added the include of mycomponent

Code: Select all

#include "mycomponent.h"
But I always got back an error when I launch idf.py build:

Code: Select all

MakeFiles/__idf_main.dir/main.c.obj   -c ../main/main.c
../main/main.c:2:10: fatal error: mycomponent.h: No such file or directory
 #include "mycomponent.h"
Could you please help me to figure out what's wrong?

Thank you!

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Custom component library

Postby chegewara » Tue Mar 03, 2020 10:12 pm

How mycomponent tree looks like? Did you put mycomponent.h in include subfolder?

You also need to add mycomponent to CMakeLists.txt in main folder:
https://github.com/espressif/esp-adf/bl ... sts.txt#L5

leonardo
Posts: 2
Joined: Sat Feb 29, 2020 6:18 pm

Re: Custom component library

Postby leonardo » Tue Mar 03, 2020 11:40 pm

Thank you very much!
It was an error placing the files in the tree. I followed your project and I was able to compile mine correctly.
Thank you again! :-)

Who is online

Users browsing this forum: axellin, Bing [Bot], Google [Bot], Majestic-12 [Bot] and 86 guests