Go Down

Topic: including a contributed library in a library header (Read 730 times) previous topic - next topic

Totoro

Hi all,
I'm new to the forum and to Arduino development. I have gotten pretty far thanks to wealth of information here. I am sure this has been asked and answered before but I haven't been able to get the correct search phrase to find it, so excuse me for asking again.
I want to include a contributed library header in my library header. I have written a library named DS1821 for the same-named Maxim/Dallas Semi temperature sensor and want to include the OneWire library (my class inherits the OneWire class). Both libraries, my DS1821 and OneWire, are in the /Users/me/documents/Arduino/libraries directory (Mac OS X 10.6). Arduino is 1.0.1.

In my header, DS1821.h, I have the lines

#ifndef DS1821_h
#define DS1821_H
#include <OneWire.h>
. . .
#endif // DS1821_h

However, my application won't compile unless I include both headers.

#include <OneWire.h>
#include <DS1821.h>
. . .

While this works just fine, what should I do to not have to include the OneWire header in my application code?
Thanks for your help!

Nick Gammon


While this works just fine, what should I do to not have to include the OneWire header in my application code?


Nothing. Think of it as a form of documentation.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Totoro

Nick, that was a quick answer! Thank you very much.
"Think of it as a form of documentation."
OK, that works for me!
- Totoro

majenko

Any libraries used within your library must also be included in the sketch your library is used in.

This is not a drawback of C++, but a drawback of the Arduino IDE.  The IDE has to know what libraries to link with the sketch to get it to work.  It cannot recurse down into the included libraries to see what libraries they rely on.

Yes, it sucks.  But that's the Arduino IDE for you.

Go Up