structuring libraries - accessing libraries from within libraries

Hello,

I am a bit confused on the library selection procedure:
First:

  • I am still using Arduino 0023 because I use chipKit MAX32 boards
  • running on windows 7
  • The base libraries can be found in the C:...\mpide-0023-windows-20120903\hardware section
  • My project can be found in C:\Users...\Documents\Arduino
  • I have a library directory in C:\Users...\Documents\Arduino\libraries

If I build a project, lets say ProjectA, it will be in C:\Users...\Documents\Arduino\ProjectA.
In this project I use a library, lets say libA, in C:\Users...\Documents\Arduino\libraries\libA
In this last directory we will see libA.h and libA.cpp
Lets assume we have a second library, libB with the file libB.h and libB.cpp.
We will find them in C:\Users...\Documents\Arduino\libraries\libB

Now the problem:
assume I want to use libB in libA which is used in projectA
projectA.h has a line #include <libA.h>
libA.h has a line #include <libB.h>
If I compile ProjectA libA.h will be found but I receive a "file not found" error on libB.h

if I put the line #include <../libB/libB.h> into libA.h I receive errors on undefined functions of libB at link time.

if I put libB.h and libB.cpp into the directory of ProjectA everythings works.

Yes, I restarted the IDE everytime I changed something in the directory hiereachy e.g. moving/creating files

Any hints?
Is there a property which tell the system where to look for libraries and how deep into the hierarchy?

Best regards

Any hints?

More than a hint. What you appear to be doing is to hide the use of a library (libB) from the sketch. You can't do that.

If you include libA AND libB in the sketch, everything will compile properly (at, at least there is a better chance that that will happen).

hobermallow:
Is there a property which tell the system where to look for libraries and how deep into the hierarchy?

No. The problem is that the Arduino IDE collects together all the files it thinks you need in your project before it invokes the compiler. It works out which library files you need based on the header files that you #included into your main sketch .ino file. If you want to include a library in your sketch then you must #include the appropriate header into your main sketch .ino file. (Yes, I think it's a daft system too.)

@PeterH:

thank you. That's something which I did not expect from other IDEs.
But if you know you can handle it. Might a point for enhancement in the future.

@PaulS:

that's what I was afraid of. But: look at the libs which are in the IDEs hardware section.
for example wiring.h in arduino has the following lines
#ifndef Wiring_h
#define Wiring_h

#include <avr/io.h>
#include <stdlib.h>
#include "binary.h"

which obviously hides the libs stdlib and binary from the scetch

Do I have to put my libs into the hardware section of the IDE or somewhere the IDE is capable of interpreting?

Hari Seldon would probably know the answer. :slight_smile:

Failing his help, you have to include the relevant libraries in your main sketch file (the .ino file). Putting includes in other places won't help.

that's what I was afraid of. But: look at the libs which are in the IDEs hardware section.
for example wiring.h in arduino has the following lines
#ifndef Wiring_h
#define Wiring_h

#include <avr/io.h>
#include <stdlib.h>
#include "binary.h"

which obviously hides the libs stdlib and binary from the scetch

And, where does wiring.h get included? Which version of the IDE still has wiring.h? Only 0023 and earlier. And, wiring.h is included in WProgram.h, which the IDE includes in every sketch.

So, stdlib.h and binary.h are NOT hidden from the sketch.