Need help for component-requirements with release/v3.3 esp-idf

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Need help for component-requirements with release/v3.3 esp-idf

Postby kenn.tran » Sun Oct 11, 2020 6:46 pm

Hi everyone,

I have problem with component requirements. Because I'm using release/v3.3 esp-idf version, so I cannot find document about component-requirements which shows how to link/include between two (2) components in project.

So my project tree is like this:

├───components
│ ├───cloud
│ │ └───include
│ ├───eth_control
│ │ └───include
│ ├───gpio_control
│ │ └───include
│ ├───sensor_control
│ │ └───include
│ └───uart_control
│ └───include
└───main

And in component.mk in top-level, I have this:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := 	components/gpio_control/include 	\
								components/uart_control/include 	\
								components/sensor_control/include	\
								components/eth_control/include		\
								components/cloud/include
								 

COMPONENT_SRCDIRS := 	components/gpio_control/	\
						components/uart_control/	\
						components/sensor_control/	\
						components/eth_control/		\
						components/cloud/
And in component.mk of "cloud", I have this:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include ../../main
Now, because my "cloud" component needs a struct defined in "sensor_control" component, so what should I write in component.mk and/or CMakeLists.txt of "cloud" component?

Many thanks...

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Need help for component-requirements with release/v3.3 esp-idf

Postby ESP_Angus » Mon Oct 12, 2020 6:33 am

Hi Kenn,

Normally you would have one component.mk file for each of components/cloud, components/eth_control, etc. and no component.mk file in the top-level "components" directory.

So for example, components/cloud/component.mk would contain:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
... and so on with very similar component.mk files for the other 4 components (eth_control, sensor_control, etc).

Regarding any "components/include" directory in your project, suggest finding a way to remove it - maybe by moving the headers into a component's header directory.

Remove any "components/component.mk" file entirely: the idea is that each component is responsible for itself.

For GNU Make, that's it - nothing else is needed. Each component should be able to include headers from any other component, provided the components are all included in the build and each include directory is in that component's COMPONENT_ADD_INCLUDEDIRS list.

**

If you want to use CMake build system instead, then you will need to add a CMakeLists.txt file instead of each component.mk file. There are two big differences to the component.mk files. The first difference is that each source file needs to be specified, rather than a directory name. For example:
https://docs.espressif.com/projects/esp ... cmakelists

The second difference applies to any component (except for "main") that needs to include headers from another component. For example, if "cloud" needs to include headers from "sensor_control":

Then components/cloud/CMakeLists.txt looks like:

Code: Select all

set(COMPONENT_SRCS "sourcefile.c")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_REQUIRES sensor_control)
register_component()
... that's it!

Some things to note:
  • COMPONENT_REQUIRES is for CMake only and will be ignored in a component.mk file
  • The component.mk files and CMakeLists.txt files are never needed at the same time. If you only wish to use one of the two possible build systems, you only need one type of file.
  • There shouldn't be any need for any component's build file to have paths that depend on the path of one component relative to the other component. Each component is intended to be self-contained, and only refers to other components by name not by path.

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Re: Need help for component-requirements with release/v3.3 esp-idf

Postby kenn.tran » Mon Oct 12, 2020 8:24 am

Hi ESP_Angus,

Thanks for your support.

I've tried your first suggestion: removing (moving include folders of those components to be in the same include folder in components/include, removing the CMakeLists.txt in each components and removing the component.mk files in the top-level folder of my project.

So I've comment out the line in my "cloud.h" which use the struct I defined in "sensor.h" and the project had been compiled fine. But then I tried to compile again with that line, it's still failed.

My new project structure:
├───components
│ ├───cloud
│ │ cloud.c
│ │ component.mk
│ │ esp32-hal-time.c
│ │
│ ├───eth_control
│ │ component.mk
│ │ control_eth.c
│ │ Kconfig.projbuild
│ │
│ ├───gpio_control
│ │ component.mk
│ │ control_gpio.c
│ │
│ ├───include
│ │ cloud.h
│ │ control_eth.h
│ │ control_gpio.h
│ │ control_uart.h
│ │ sensor.h
│ │
│ ├───sensor_control
│ │ component.mk
│ │ sensor.c
│ │
│ └───uart_control
│ component.mk
│ control_uart.c

└───main
component.mk
hello_world_main.c
main.h

I modified my component.mk in "main" folder like this:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := 	. 					    \
								../components/include
								
COMPONENT_SRCDIRS := .

And in component.mk of my "cloud" component:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := ../include

COMPONENT_SRCDIRS := .
And the line I have in my cloud.h (use struct defined in "sensor_control"):

Code: Select all

funcionx( ... , radio_msg_t radio_msg);
And the error I get when I try to compile the project with that line:

Code: Select all

make[1]: *** [/home/.../esp/esp-idf/make/component_wrapper.mk:290: sensor.o] Error 1
make: *** [C:/msys32/home/.../esp/esp-idf/make/project.mk:552: component-sensor_control-build] Error 2
make: *** Waiting for unfinished jobs....
Do you have any suggestion?

P/s: I develop this project with Eclipse and esp-idf release/v3.3

Thanks

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Re: Need help for component-requirements with release/v3.3 esp-idf

Postby kenn.tran » Wed Oct 14, 2020 8:09 am

Hi guys,

I think I solved the problem. So the problem could be because I use both
component.mk (not empty)
and

Code: Select all

CMakeList.txt
files.

What I have changed? So I removed everything in all

Code: Select all

component.mk
files but still keep component.mk files in each component folder along with CMakeList.txt file.

And in

Code: Select all

cloud
component, I add to CMakeList.txt this line

Code: Select all

set(COMPONENT_REQUIRES sensor_control)
.

Eventually, I recompiled project and it works.

Thanks for your support.

Who is online

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