Hello everyone,
I have a problem with including one library in another and conversely, if I use #include in both I generate a recursion and it doesn’t work.
I have tried declaring class Can; (as you can see below) but I get the error that it can’t find the file mac.h
If I use only the can library (can.h and can.cpp) everything works and the lib mac.h also finds it and works
I have updated the code above, I had voluntarily omitted parts so as not to make it too complex, but I had actually omitted too much for it to be readable.
In the meantime I saw your solution, I had also tried this way of putting the class declarations inverted for both files but I always get that the mac.h library does not exist
lib/Can/src/Can.h:12:10: fatal error: Mac.h: No such file or directory
I also have other libraries included before and those don’t give me any problems just as they don’t give me problems if I just use the can library obviously removing any reference to the mb library
I tried editing the code by only putting class declarations as suggested in your code but unfortunately I also have custom structures in mb.h before the actual class declaration and if mb.h is not actually included in can.h these are not seen.
So I tried putting these structures in a separate file mbStruct.h and this included in both mb.h and can.h.
Now the problem that does not include me mac.h has moved to mbStruct.h this I think because it is the last one I put in and once I have solved this I will also get the mac.h insertion error again
I hope I have illustrated the steps well
I don’t think libraries located in /lib have access to files located in /include.
Usually only the project itself have access to files located in /include.
I have tried it and so I no longer get the error in MbStruct, but the error in MacAddress.h has returned.
In file included from lib/Mb/src/Mb.cpp:2:
lib/Can/src/Can.h:12:10: fatal error: MacAddress.h: No such file or directory
********************************************************************
* Looking for MacAddress.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:MacAddress.h"
* Web > https://registry.platformio.org/search?q=header:MacAddress.h
*
********************************************************************
12 | #include "MacAddress.h"
| ^~~~~~~~~~~~~~
compilation terminated.
What I don’t understand is that MacAddress.h is included twice as can.h I include it from both can.cpp and mb.cpp and this generates an error when I include it the second time (from mb.cpp)