Library path

Hi,

I read the tutorial about this topic (https://www.arduino.cc/en/Guide/Libraries#)

But we can often find many librairies for the same device, i.e. many lib about LCD displays, DS1307RTC device, ... and they are not mutually compatible; I can need the 1st one for a sketch and the 2nd one for another sketch.

So in this case, how can I use a local lib, without installing it in the dedicated folder in the arduino tree ?
Is it by using different characters (as #include"" or #include<>) in the lib declaration in the sketch ?
What is the meaning of these 2 different declarations ?

I tested some examples but without success.
Thank you for yout help.

Regards

In a perfect world, library authors would use original names for their header files, rather than giving them incredibly generic names like DS1307.h, which are bound to cause conflict with the other installed libraries written by similarly uncreative authors.

But the world is imperfect and so we have name collisions. If you are using the Arduino IDE, you could deal with this by simply picking the best library to use in all your sketches, and only installing that one. For users of the Arduino Web Editor, the problem is much more serious because all the thousands of libraries in the Arduino Library Manager index are pre-installed and there is no way to uninstall them.

Say you really did want to use multiple conflicting libraries in your various sketches. If you're using the Arduino IDE, a solution is to install the library to the src subfolder of the sketch folder. For example, lets say you have a sketch named "Foo" and a library named "DS1307". The folder structure would look something like this:

Foo/
|_foo.ino
|_src
   |_DS1307
      |_DS1307.h
      |_DS1307.cpp

Then your #include directive would look like this:

#include "src/DS1307/DS1307.h"

When doing that, you might find that some libraries need their #include directives updated. For example, lets say DS1307.cpp has this line:

#include <DS1307.h>

Although technically incorrect, that would have worked fine when the library was installed normally, so you will see this issue frequently with Arduino libraries. The solution is to change it to:

#include "DS1307.h"

It gets a little more tricky when you have multiple libraries installed to the src subfolder which each have dependency on each other. In that case, you need to specify the relative path from one to the other in their #include directives. For example, lets say the "DS1307" library has a dependency on the "Bar" library, which is also installed to the src subfolder. If DS1307.h originally had this #include directive:

#include <Bar.h>

You would need to change it to:

#include "../Bar/Bar.h"

Unfortunately, Arduino Web Editor does not support the src subfolder of the sketch folder, so you can't use this solution there. In that case, you would have no alternative other than to put the library files right in the root of the sketch folder. That could get pretty cluttered if you had multiple libraries thrown in there and each of the library source files will show up as a tab in the Arduino Web Editor/Arduino IDE, which could make it more confusing because the library code will not be hidden away.

windo:
Is it by using different characters (as #include"" or #include<>) in the lib declaration in the sketch ?
What is the meaning of these 2 different declarations ?

#include <Foo.h> causes the standard library folders to be searched for the file.

#include "Foo.h" causes the current folder to be searched for the file. If it's not found there, the standard library folders will be searched for the file.

2 Likes

Thank you for this complete and detailed explanation.
I'll try the solution.

I hope this will help other non specialists as I am.

Regards.
Dominique