Including reference to library from within a library

I’m creating a library which uses another library that I’ve written.

The first library is in the correct location E:\arduino-1.0\libraries\clsTimer

I thought I would just reference the library header in the second library using:

#include <clsTimer.h>

However the IDE doesn’t like this and shows:

E:\arduino-1.0\libraries\clsApp/clsApp.h:31:24: error: clsTimer.h: No such file or directory
In file included from tmrTest.cpp:13:
E:\arduino-1.0\libraries\clsApp/clsApp.h:52: error: ISO C++ forbids declaration of ‘clsTimer’ with no type
E:\arduino-1.0\libraries\clsApp/clsApp.h:52: error: expected ‘;’ before ‘*’ token

How do I resolve the location of the first library?

in your sketch file you need to include your library. and also any library that your library includes.

I tried that, but it doesn't like that either.

include "../clsTimer/clsTimer.h"

This seems to work tho...

Scratch that…still get warnings…here is what I’ve tried.

In my sketch:
#include <clsTimer.h>
#include <clsApp.h>

The class ‘clsApp’ references the class ‘clsTimer’ this causes the following when verified:

In file included from E:\arduino-1.0\libraries\clsApp\clsApp.cpp:11:
E:\arduino-1.0\libraries\clsApp/clsApp.h:51: error: ISO C++ forbids declaration of ‘clsTimer’ with no type
E:\arduino-1.0\libraries\clsApp/clsApp.h:51: error: expected ‘;’ before ‘’ token
E:\arduino-1.0\libraries\clsApp\clsApp.cpp:43: error: expected constructor, destructor, or type conversion before '
’ token

So instead I moved the reference to clsTimer.h inside clsApp.h:
#include <Arduino.h>
#include <clsTimer.h>

When verified:
In file included from tmrTest.cpp:13:
E:\arduino-1.0\libraries\clsApp/clsApp.h:31:24: error: clsTimer.h: No such file or directory
In file included from tmrTest.cpp:13:
E:\arduino-1.0\libraries\clsApp/clsApp.h:52: error: ISO C++ forbids declaration of ‘clsTimer’ with no type
E:\arduino-1.0\libraries\clsApp/clsApp.h:52: error: expected ‘;’ before ‘*’ token

#include <clsTimer.h> and #include “clsTimer.h” look for the file in different places. Try changing <> to “”.

Thank you Paul, I’ve tried that too…normally <> looks at the environment to see where to search for headers, “” normally means look in the current working folder, ie. the same folder as the file referencing it.

The other libraries that are part of the default build only reference headers from stock, I can’t see a library that references another library.

Oddley, if I put:
#include <Arduino.h>
#include “clsTimer.h”

Inside the header clsApp.h

and:
#include <clsApp.h>
#include <clsTimer.h>

Into the sketch source, it will verify without any warnings.

Note: If I remove <clsTimer.h> from the sketch it fails to verify without warnings, which I don’t understand, as I would have thought that including the file in clsApp.h would be enough.

Note: If I remove <clsTimer.h> from the sketch it fails to verify without warnings, which I don’t understand, as I would have thought that including the file in clsApp.h would be enough.

You have to understand how the IDE works. It copies your sketch to a temporary folder. It copies any files referenced by your sketch (those that are #included) to the same folder, and copies the corresponding .cpp files.

So, if you have clsApp.h in the sketch, but not clsTimer.h, the sketch and clsApp.h and clsApp.cpp will be copied to the temp. folder. Only the files in the temp. folder are compiled. Since clsTimer.h was not referenced by the sketch, it was not copied, and is not available for clsApp.h or clsApp.cpp to include.

When clsTimer.h IS included in the sketch, it is copied, and clsApp.h/clsApp.cpp can reference it.

The IDE does not recursively scan files to know what really needs to be copied/compiled.

Thanks that makes sense and worth knowing!