Robert Atkins Robert Atkins - 2 months ago 4x
C++ Question

Is it possible to include a library from another library using the Arduino IDE?

I'm trying to write an Arduino library (effectively a C++ class) which itself references another library I have installed in my Mac's ~/Documents/Arduino/libraries directory.

At the top of the .cpp of the library I'm writing, I've tried

#include <ReferencedLibrary.h>


#include "ReferencedLibrary.h"

... neither of which work. I can successfully
#include <ReferencedLibrary.h>
from sketches in my ~/Documents/Arduino directory. Am I missing something or is this a limitation of the Arduino IDE/makefile? Is there a workaround?


The documentation here states:

The include path includes the sketch's directory, the target directory (/hardware/core//) and the avr include directory (/hardware/tools/avr/avr/include/), as well as any library directories (in /hardware/libraries/) which contain a header file which is included by the main sketch file.

This means that if you #include "ReferencedLibrary.h" from your main sketch file, this causes that file's libraries directory to get added to the include path for other libraries to include. A bit of a hack but it does work on my Mac.