Trying to make component folder work

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Trying to make component folder work

Postby zliudr » Sat Jan 02, 2021 11:39 pm

I have an external component folder called iot_device_common_files in the same parent folder as my project's folder iot_device
which includes .h and .cpp files.
In my project I have in Makefile:
EXTRA_COMPONENT_DIRS += $(IOT_DEVICE_COMMON_FILES_PATH)

So I have #include like this:
#include "../../iot_device_common_files/defs.h"

This works because the relative path goes from iot_device/main two levels up and into the common folder and refers to defs.h.

My next step is to include components the proper way. I want to include some FTDI USB-UART support so I created under the common folder. I'm mimicking what esp_https_client component is doing to set up some files. Just trying to log my progress here for now and I'm sure I'll encounter errors and need some help :)
Hope this thread when complete will help other set up their component folders ;)

ESP_Jan
Posts: 42
Joined: Tue Dec 01, 2020 10:56 am

Re: Trying to make component folder work

Postby ESP_Jan » Mon Jan 04, 2021 5:38 am

Hi zliudr,

be sure to check the documentation on the build system, mainly the example project to get to know how the components work in the build system.

Jan

rootgordon
Posts: 3
Joined: Mon Jan 04, 2021 4:45 pm

Re: Trying to make component folder work

Postby rootgordon » Tue Jan 05, 2021 10:16 am

Hi everyone,

this is exactly what I'm having trouble with, so I'll post this here:

For context: I'm working on a project that includes the SGTL5000. I'll have to communicate with that chip via i2c, which is why I'm writing some functions that I would like to be able to easily use in other projects as well.

What I've got so far:
- working esp-idf-setup (v4.2/stable)
- project-folder with the standard (minimal) CMakelist.txt
- "components"-folder inside the project-folder, containing one subdirectory: "sgtl5k"
- inside "sgtl5k"-subdirectory: sgtl5k.h, sgtl5k.c, CMakelist.txt

Here's the CMakelist from the sgtl5k-subdirectory:

Code: Select all

idf_component_register(
      SRCS "sgtl5k.c"
      INCLUDE_DIRS "."
      )
The CMakelist.txt inside the main directory is also the untouched version from the template.

I have read through the documentation zliudr posted several times now and I can't seem to find (or understand) some crucial information:

- I still have to include sgtl5k.h like this in my main.c:

Code: Select all

#include "../components/sgtl5k/sgtl5k.h"
From what I understand, shouldn't

Code: Select all

#include "sgtl5k/sgtl5k.h"
be enough? that's not a huge problem though, just shows me I'm misunderstanding something (which might lead to the actual problem).

- When I'm running idf.py build, I get the error "undefined reference to sgtwrite" in main.c, sgtwrite being a function from my sgtl5k-library.

I'd very much appreciate the help here since I've been reading the docs so many times now and I still can't seem to find the mistake I'm making. Any changes I've tried making to the CMakelist.txts so far felt like complete stabs in the dark, so please understand that I'll refrain from posting what I tried there to no avail.

Cheers

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: Trying to make component folder work

Postby boarchuz » Tue Jan 05, 2021 11:38 am

Should only need this:

Code: Select all

#include "sgtl5k.h"
Try adding sgtl5k to REQUIRES in project-folder/main/CMakeLists.txt

rootgordon
Posts: 3
Joined: Mon Jan 04, 2021 4:45 pm

Re: Trying to make component folder work

Postby rootgordon » Tue Jan 05, 2021 2:42 pm

Ok, changed the include and modified CMakelist.txt in main:

Code: Select all

# Edit following two lines to set component requirements (see docs)
   set(COMPONENT_REQUIRES "sgtl5k" )
   set(COMPONENT_PRIV_REQUIRES )
   
   set(COMPONENT_SRCS "main.c")
   set(COMPONENT_ADD_INCLUDEDIRS "")
   
   register_component()
Now I get:

Code: Select all

Failed to resolve component 'sgtl5k'.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: Trying to make component folder work

Postby boarchuz » Wed Jan 06, 2021 12:46 am

Check these files are exactly "CMakeLists.txt"

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Trying to make component folder work

Postby ESP_Sprite » Wed Jan 06, 2021 1:20 am

boarchuz wrote:
Wed Jan 06, 2021 12:46 am
Check these files are exactly "CMakeLists.txt"
Specifically, note the S at the end: CMakeLists.txt.

rootgordon
Posts: 3
Joined: Mon Jan 04, 2021 4:45 pm

Re: Trying to make component folder work

Postby rootgordon » Wed Jan 06, 2021 11:52 am

boarchuz wrote:
Wed Jan 06, 2021 12:46 am
Check these files are exactly "CMakeLists.txt"
Thank you so much! The s in the end wasn't missing anywhere, but the L wasn't capitalized for sgtl5k. Now the compiler is finally complaining about my disastrous first-draft-functions in sgtl5k.c :lol: But that I can handle. I never would have noticed this after going over everything so many times. Appreciate the help!

Who is online

Users browsing this forum: Bing [Bot] and 400 guests