How to include library inside another library?

This is my first post, so I hope I’m in the right place…

While learning the development environment, I was trying to build a library (Led13) that uses other libraries (TimerOne), but I’m having problems including the header for one library inside the other library. The code is shown below. BTW… While debugging Led13, I left it in the same folder as the sketch.

For some reason, the line "TimerOne *timer; results in an error (basically TimerOne is undefined) unless I also add a #include <TimerOne.h> in the sketch! Any idea what’s going on? Why should that be necessary?

See the lines marked with “<<<<<” below

Here’s the library (Led13) that I would like to include TimerOne in…

#include "Led13.h"
#include <arduino.h>
#include <TimerOne.h>

byte pinNumber = 13;
boolean isOn = false;
TimerOne *timer;              <<< TimerOne is undefined unless I uncomment the #include <TimerOne> line in the sketch!

Led13::Led13(void)
{
	pinMode(pinNumber,OUTPUT);
}
Led13::Led13(int intensity)
{
	pinMode(pinNumber,OUTPUT);
}

Led13::~Led13(void)
{
}

void Led13::on()
{
	digitalWrite(pinNumber,HIGH);
}
void Led13::off()
{
	digitalWrite(pinNumber,LOW);
}

void Led13::toggle()
{
	if (isOn)
	{
		off();
		isOn = false;
	}
	else
	{
		on();
		isOn = true;
	}
}

Here’s the sketch…

#include "Led13.h"
//#include <TimerOne.h>   <<<< If I uncomment this line out, the problem goes away.

Led13 *led;

void setup()
{
	led = new Led13();
}

void loop()
{
  /* add main program code here */
	led->toggle();
	delay(500);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

#include <arduino.h>

Do a favour to your Linux and Mac brethren and use the correct filename…

#include <Arduino.h>

Any idea what's going on?

Yes. The IDE uses the include list from the sketch to determine which libraries should be included in the build.

Why should that be necessary?

I have no idea why the IDE works that way. The next 1.5 release will very likely not have the limitation.

It's just the way it's always been. If you don't like it, then you should use UECIDE which does things properly by recursing into the headers of your included libraries to find their requirements.

No problem... I thought it was something I was doing. I'm fine as long as it's working the way it's supposed to. :smiley:
Thanks for the quick response!

Do you know whether it's actually planned for fixing in 1.5?

PeterH:
Do you know whether it's actually planned for fixing in 1.5?

Christian published a patch, the discussion about the patch was brief, and there were no objections. As far as I can tell, in those circumstances he includes such changes in the next release.

If you have the time and the means please give it a try...

...and add your 2¢ to the Developers List / Google Group.