Skip to main content
Arduino

Return to Revisions

2 of 2
replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/

Referencing local libraries from higher dir levels

How can I include libraries not contained in any direct subdirectories of a sketch, using the Arduino IDE?

I want my project structure to look like this:

Project
└> MCUa
 └> MCUa.ino
└> MCUb
 └> MCUb.ino
└> Libraries
 └> TimerLib
 └> TimerLib.cpp
 └> TimerLib.h

So in my project two sketches MCUa and MCUb share a resource, namely the library TimerLib.

I've tried to include the libraries like this:

#include "../Libraries/TimerLib/TimerLib.h"

or this:

#include "./../Libraries/TimerLib/TimerLib.h"

But none of them will compile - this is the error message:

fatal error: ./../Libraries/TimerLib/TimerLib.h: No such file or directory
 #include "./../Libraries/TimerLib/TimerLib.h"
 ^
compilation terminated.
exit status 1
Error compiling.

If I put the library directly in of the directories and reference it like this:

#include "./Libraries/TimerLib/TimerLib.h"

Everything goes well.

Using an absolute path like in this answer is not a possibility in this case, as it should compile out of the box for others, without modifying any absolute paths.

Clausen
  • 161
  • 2
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /