Duplication of libraries (how to use customized lib instead of the default one)

Hello everyone!

I have noticed that in the last few versions of the Arduino IDE the library TinyWireM is included by default (although it's not in "\Arduino\libraries" folder but instead in "Documents\Arduino\libraries\TinyWireM"). And this is great but that causes a small problem for me.

Since I'm trying to make a board package, when this library wasn't embedded in the installation I was doing that manually. Now this is not necessary. But my problem is that I had to make a small change inside the library (increasing the USI_BUF_SIZE from 18 to 30), because otherwise my examples don't work correct. And now when I compile any of the sketches the compiler finds that there is a duplication of the header name and uses the one from the "Documents\Arduino\libraries\TinyWireM" instead of the customized one located inside my package.
At first I thought to remove my library and to instruct the users of the package to change this macro value manually by editing the header file. But this is first uncomfortable for the user and second (maybe worse) this may cause other examples that use this library to behave wrong.

So I tried to rename my customized files to: "_TinyWireM.cpp; _TinyWireM.h; _USI_TWI_Master.cpp; USI_TWI_Master.h" and now it works but this looks more like a workaround instead of solution. And I have to make a change in all of the examples to include the header files with the prefix ''.

So my questions are:

  1. Is it possible somehow to change the priority of the "include library directories" where the compiler looks for header files?
  2. Is it possible to change the content of those default files when the package is installed?
  3. Is there any other way (other than the one I mentioned above) to bypass the default library?

Best regards!
Stan

Have you considered (and tried) the use include "yourlib.h" instead of include <yourlib.h> in your sketch

The library needs to be in the same directory as the sketch.

Stanimir5F:
I have noticed that in the last few versions of the Arduino IDE the library TinyWireM is included by default (although it's not in "\Arduino\libraries" folder but instead in "Documents\Arduino\libraries\TinyWireM").

It's not included with the IDE, you must have installed the library there. Probably there was an updated version of that library released by Adafruit that you installed via Library Manager, which installs libraries to the {sketchbook}\libraries folder.

Stanimir5F:
when this library wasn't embedded in the installation I was doing that manually. Now this is not necessary.

It's still necessary because it's not embedded in the IDE installation. If Library Manager updates overriding your library will cause issues for the users of your package I recommend changing the name field in the library.properties file of the TinyWireM library bundled with your package to a unique value. That way the users will not get updatable library notifications or see the library under Type: updatable in Library Manager whenever Adafruit releases a newer version than the one bundled with your package. The override issue will still occur if the user intentionally installs the Adafruit version of TinyWireM but this will at least reduce the chances of unintentional installation.

Stanimir5F:

  1. Is it possible somehow to change the priority of the "include library directories" where the compiler looks for header files?

Yes, but only in Arduino IDE v1.6.9 and onward. If you change the architectures value in the library.properties file of the TinyWireM library included with your package to match the architecture of your package(avr I'd assume) then that library will take priority over the Adafruit version in the sketchbook}\libraries folder because it matches the architecture of the board exactly instead of the wildcard match of the Adafruit version(see Handle priority inversion for promoted bundled libraries by facchinm · Pull Request #123 · arduino/arduino-builder · GitHub). In IDE versions previous to 1.6.9 the library in the sketchbook folder will always override the one included with your package.

This is a serious negative side effect of Library Manager. Various solutions have been discussed at length(lib manager overrides core libraries included with 3rd party boards · Issue #4064 · arduino/Arduino · GitHub) but the "priority inversion" seems to be as far as the Arduino developers are willing to go towards fixing the issue. In your case priority inversion does solve the issue since Adafruit used the wildcard in the architectures field(though I'm not sure why since it seems to be an avr-only library) but with other libraries that already explicitly define the architecture of your package there's no workaround other than renaming your library or documenting how the users can work around the issue.