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

Robert Atkins picture Robert Atkins · Jun 28, 2011 · Viewed 22.5k times · Source

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>

and

#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?

Answer

julioterra picture julioterra · Nov 22, 2011

I have been able to include a library in another Arduino library by using a relative path. For example, to include the AbstractSwitch library into the DigitalSwitch library, assuming that both of these libraries live in their own separate folders within Arduino's standard library folder, you can use the following include statement:

#include "../AbstractSwitch/AbstractSwitch.h"

In other words, your include statement should read:

#include "../LibraryFolder/LibraryHeaderFile.h"