Component manager with circular dependencies
Posted: Thu Jun 05, 2025 10:58 am
I am trying to understand how IDF Component Manager deals with circular dependencies.
I have 2 components: "component_a" and "component_b" and they depend on each other
This is component_a.c:
And this is component_b.c:
Since one needs the other, they declare the corresponding dependency.
This is idf_component.yml inside component_a:
And this is idf_component.yml inside component_b:
Ok so now I create a new project and from this one I just want to use "component_a" so idf_component.yml inside the new project looks like this:
And the source file just calls a function from "component_a" like this:
If I compile it like this, then IDF Component Manager enters into a circular dependency loop and fails:
The only way I can see to solve this is removing the dependencies of "component_a" and "component_b" and handle all the required dependencies in the main project.
This doesn't seem to be the perfect solution because this way I need to know all the dependencies needed by every component used, even components that I don't want to use directly in the main project (like component_b in this example)
Shouldn't the IDF Component Manager be able to handle this circular dependencies issue? Am I missing something here?
I also attach the vscode project that illustrates this example for better understanding.
Thank you.
I have 2 components: "component_a" and "component_b" and they depend on each other
This is component_a.c:
Code: Select all
#include <stdio.h>
#include "component_a.h"
#include "component_b.h"
void funcA(void)
{
printf("Function A from Component A\n");
funcD();
}
void funcC(void)
{
printf("Function C from Component A\n");
}And this is component_b.c:
Code: Select all
#include <stdio.h>
#include "component_b.h"
#include "component_a.h"
void funcB(void)
{
printf("Function B from Component B\n");
funcC(); // Call function from Component A
}
void funcD(void)
{
printf("Function D from Component B\n");
}Since one needs the other, they declare the corresponding dependency.
This is idf_component.yml inside component_a:
Code: Select all
dependencies:
component_b:
path: ../component_bAnd this is idf_component.yml inside component_b:
Code: Select all
dependencies:
component_a:
path: ../component_aOk so now I create a new project and from this one I just want to use "component_a" so idf_component.yml inside the new project looks like this:
Code: Select all
dependencies:
component_a:
path: ../my_components/component_aCode: Select all
#include <stdio.h>
#include "component_a.h"
void app_main(void)
{
funcA();
printf("Circular dependency example completed.\n");
}
If I compile it like this, then IDF Component Manager enters into a circular dependency loop and fails:
The only way I can see to solve this is removing the dependencies of "component_a" and "component_b" and handle all the required dependencies in the main project.
This doesn't seem to be the perfect solution because this way I need to know all the dependencies needed by every component used, even components that I don't want to use directly in the main project (like component_b in this example)
Shouldn't the IDF Component Manager be able to handle this circular dependencies issue? Am I missing something here?
I also attach the vscode project that illustrates this example for better understanding.
Thank you.