Controlling library file compilation.

In the old days, as I understood it, you put your aftermarket library files in a folder called library in the Arduino folder an everything just seem to work. Simple simple.

Now, it seems the IDE is hiding and managing these for you and this is causing me issues. I have my favorite flavors of aftermarket files in the old library folder, but now its finding other versions of these. Some by the original creator, others as faster versions created by different processor makers.

How does one manage this? Are there controls somewhere?

thanks!

-jim lee

jimLee:
In the old days, as I understood it, you put your aftermarket library files in a folder called library in the Arduino folder an everything just seem to work.

Sketch folder. Do not put anything in the same directory tree as arduino.exe.

For the rest, you are probably going to have to provide a concrete example.

An example:

Multiple libraries were found for "SD.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
 Not used: /Applications/Arduino.app/Contents/Java/libraries/SD

-jim lee

When multiple libraries contain a file that matches the #include directive, it attempts to automatically chose the correct one. There are a few factors that influence the library priority:

  • Architecture matching: The library may define an architectures field in its library.properties metadata file. Priority is given according to: exact match > wildcard match > mismatch. If no architectures field is defined, that's considered a wildcard match.
  • File/folder name match: The file that matches the folder name exactly gets priority.
  • Library location: Priority is given according to which libraries folder the library is in: sketchbook > hardware package > IDE.

In your example, both SD libraries have architectures value of * so they get equal priority. Both have the same folder name, so they get equal priority. So it comes down to the location, which gives priority to the SD library bundled with the Teensy hardware package.

In this case, I think the best solution is to install your preferred SD library to the libraries subfolder of your sketchbook folder to give it priority.

A workaround I have found useful in other cases is to add an #include directive for a file unique to your preferred library before the #include directive for the file with the common name. That will force the library which contains the unique file to be used. I have even resorted to adding a dummy .h file with a unique name to the preferred library in cases where it does not already have a file with a unique name. Although a bit hacky, this technique has saved the day several times with the Arduino Web Editor, where this problem is much more common due to it having the thousands of Arduino Library Manager libraries pre-installed and not allowing the user any control over the file system.