Competing libraries in different folders: how to solve?

A program calls for a library (in this case SdFat.h) in

\home\user\arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266SdFat

but an identical libary exists in

C:\Users\xxx\Mijn Drive\documents\Arduino\libraries\SdFat

Is there a way to direct a sketch to use libraries in a specific location, different from the default \Arduino\libraries folder?

If the library is really identical then it would not matter which one was used

However, what happens in practice is that the IDE uses the appropriate library for the board selected in the IDE

What is is that you are trying to do ?

Both SdFat.h libraries are identical in name but not in contents.

The program needs to use the SdFat.h library in the

\home\user\arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266SdFat

location but the compiler defaults to

C:\Users\xxx\Mijn Drive\documents\Arduino\libraries\SdFat

..in other words, the compiler does use the wrong of both, not what is deemed appropriate for the sketch.

Hence my question: is it possible to have the sketch direct the compiler to a specific library location for a specific library?

Which board have you got selected in the IDE ?

ESP8266 (boards v3.1.2).

Which actual board do you have ?

ESP8266.

But the issue is to get the compiler to be directed to a specific library.

Regardless of the board.

The ESP8266 is a chip

Which board do you have

ESP8266 NodeMCU, ESP8266 generic, ESP8266 Wroom, ESP8266 Thinker,...

Can you please tell me what the relevance is with respect to my question in OP:
"

Is there a way to direct a sketch to use libraries in a specific location, different from the default \Arduino\libraries folder?
"

As I said previously

This, of course, might not be working

Taking your ESP8266 NodeMCU as an example, exactly which board do you select in the IDE and which version of the IDE are you using ?

When you compile for a ESP8266 and you do an include with
#include "SdFat.h"
the compiler will use the "ESP8266SdFat"

if for any reason you want to use the

C:\Users\xxx\Mijn Drive\documents\Arduino\libraries\SdFat

on a ESP8266 you coud add an additional SdFatOem.h in the Arduino SdFat and include that SdFaetOem.h.
That SdFatOem.h should include the SdFat.h

// noiasca just a short test
#include "SdFat.h"

now you you change the sdinfo sketch to include the the OEM version:

//#include "SdFat.h"  // candidates: [SdFat@2.2.2 ESP8266SdFat@2.0.2]
#include "SdFatOem.h" // candidates: [SdFat@2.2.2]
#include "sdios.h"

But I assume there is a reason why the ESP8266 provides a core specific library anyway.

The only way I'm aware of to force the compiler to use a specific library is to put a uniquely named header file in the library folder and include that first. File can be completely empty.

1 Like

@noiasca Just to confirm, and if I understand correctly, then simply using, for this particular library (where two identically named libraries exist in

\home\user\arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266SdFat

..and in

C:\Users\xxx\Mijn Drive\documents\Arduino\libraries\SdFat

where the compiler (wrongly) assumes appropriate to use the library in the latter directory,
..then using in the sketch

#include "SdFat.h"

will force the compiler to use the library in the first directory above?

But it also requires the duplicate -wrongly used- library SdFat.h in the original \Arduino\libraries folder to be renamed?

@david_2018 ..if i understand correctly, basically renaming one of both identically named libraries?

no it's the other way round.
by default based on the chosen board ESP8266 the Compiler will use ESP8266SdFat
if you want to use the Arduino library with the ESP8266, my described workaround will work and the SdFat library will be included.
No folder needs to be renamed. It's just this additional file in the Arduino Library.

When the sketch gets compiled you should be able to see, what library the IDE has chosen ("candidate").

@noiasca Thanks for your fast reply.
What is strange is that the case I have (had, I now deleted the \Arduino\libraries\SdFat library) the compiler choose this latter library instead of the one residing in

\home\user\arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266SdFat

@noiasca

When the sketch gets compiled you should be able to see, what library the IDE has chosen ("candidate").

Indeed, that is how I discovered the wrong of both SdFat.h libraries was used.

You never did answer these questions

As has been explained a couple of times in this topic, the board that you have selected in the IDE should determine which library is used

@UKHeliBob

As has been explained a couple of times in this topic, the board that you have selected in the IDE should determine which library is used

"..should.."

Indeed. But it did not, as explained in my posts.

For one last time

Which board do you have selected in the IDE ?