Depencies problem, how far it goes?

Hi,

I have some folder structure like that :

\_lib
  \_lib1
   \_lib1.h
   \_lib1.cpp
  \_lib2
   \_lib2.h
   \_lib2.cpp
[...]

And my code was compiling until i made some clean inside .h for redundant call. Now it is like that :

main.h ;
#include "lib1.h"

lib1.h :
#include "lib2.h"

lib2.h :
#include "lib3.h"
#include "lib4h"

And i get that error :

fatal error: lib3.h: No such file or directory

But, if i add lib3/lib4 inside lib1 its ok (there are not need there):

main.h ;
#include "lib1.h"

lib1.h :
#include "lib2.h"
#include "lib3.h"
#include "lib4h"

lib2.h :
#include "lib3.h"
#include "lib4h"

Is it normal ? PlatformIO related or precompiler related ?

Thanks in advance

What does the complete folder structure of this project look like?

Was created with platformio

_include
_lib
__lib1
____lib1.cpp
____lib1.h
[...]
_src
__main.cpp
__main.h
_test

That doesn’t look like the complete folder structure…

So you have 4 libraries in your lib folder (lib1 to lib4) ??

Is there a lib3.h present?

I have 8 libs which i wrote, its why i didn’t put them :wink:
The directory structure are all the same, for example a SPI/I2C lib :

SPI
\_SPI.h
\_SPI.cpp
I2C
\_I2C.h
\_I2C.cpp

And they partially depends on each other?

Any chance to get a look at your project? (github?)

Sorry, you edit/reply faster than me :wink:
I edited previous post

No github for now, they depends each other with no loop call (in case of)

and yes, lib3 exist, if i call it from lib1, compilation work

It’s not about where libraries are called from.
This whole thing is ONE project.

Let me prepare an example…

Example:

File structure:

.
├── lib
│   ├── LibA
│   │   ├── LibA.cpp
│   │   └── LibA.h
│   └── LibB
│       ├── LibB.cpp
│       └── LibB.h
├── src
│   └── main.cpp
└── platformio.ini

lib/LibA/LibA.h

#pragma once

int function_from_libA();

lib/LibA/LibA.cpp

#include "LibA.h"

int function_from_libA() {
    return 42;
}

lib/LibB/LibB.h

#pragma once

int function_from_libB();

lib/LibB/LibB.cpp

#include "LibB.h"
#include "LibA.h"

int function_from_libB() {
    return function_from_libA() + 1; // should be 43
}

src/main.cpp

#include <Arduino.h>
#include <LibB.h>

void setup() {
    Serial.begin(115200);
    Serial.println(function_from_libB());
}

void loop() {}

LibB depends on LibA - No issues here…

Output:

43

Working on it, i try to reproduce it with simple archi like yours.

finally, was my mistake (as usual ? ^_^)

I got 2 .cpp inside a lib, i moved it in another folder and now it works. I don’t understand why it works if i call another lib before.

Thanks for your work

1 Like

Without seeing the code I can only guess.

Maybe it’s because you included some header files in another header file…
But that’s just a gues.

I’m glad you were able to fix it :slight_smile:

1 Like