compiler - selecting libraries

Hello,

have some Trouble with a new application and I suppose that it could be related to some included libraries.
From the following Compiler Output I see

Alternatives for OneWire.h: [MAX31850_OneWire@1.0.2 OneWire@2.3.5 OneWire-2.3.3.06@2.3.3]
ResolveLibrary(OneWire.h)
-> candidates: [MAX31850_OneWire@1.0.2 OneWire@2.3.5 OneWire-2.3.3.06@2.3.3]

How do I know which library will be used?
How can I clearly define which library shout be used by the Compiler?

"C:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/lwip2/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Temp\\arduino_build_876866/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_191024=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10810 -DARDUINO_ESP8266_WEMOS_D1MINIPRO -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_WEMOS_D1MINIPRO\"" -DFLASHMODE_DIO -DESP8266 "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\cores\\esp8266" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\variants\\d1_mini" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\ESP8266WiFi\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\ESP8266WebServer\\src" "-ID:\\Dokumente\\Arduino\\libraries\\WebSockets\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\Hash\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\Wire" "C:\\Users\\MiKo\\AppData\\Local\\Temp\\arduino_build_876866\\sketch\\THP-Sender_hw069_sw0085.ino.cpp" -o nul
Alternatives for OneWire.h: [MAX31850_OneWire@1.0.2 OneWire@2.3.5 OneWire-2.3.3.06@2.3.3]
ResolveLibrary(OneWire.h)
  -> candidates: [MAX31850_OneWire@1.0.2 OneWire@2.3.5 OneWire-2.3.3.06@2.3.3]
"C:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/lwip2/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\\Users\\MiKo\\AppData\\Local\\Temp\\arduino_build_876866/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_191024=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10810 -DARDUINO_ESP8266_WEMOS_D1MINIPRO -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_WEMOS_D1MINIPRO\"" -DFLASHMODE_DIO -DESP8266 "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\cores\\esp8266" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\variants\\d1_mini" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\ESP8266WiFi\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\ESP8266WebServer\\src" "-ID:\\Dokumente\\Arduino\\libraries\\WebSockets\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\Hash\\src" "-IC:\\Users\\MiKo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.1\\libraries\\Wire" "-ID:\\Dokumente\\Arduino\\libraries\\OneWire" "C:\\Users\\MiKo\\AppData\\Local\\Temp\\arduino_build_876866\\sketch\\THP-Sender_hw069_sw0085.ino.cpp" -o nul

snaudi:
How do I know which library will be used?

At the end of the compilation output, you should see something like:

Multiple libraries were found for "OneWire.h"
 Used: E:\arduino\libraries\OneWire
 Not used: E:\arduino\libraries\OneWire-2.3.5
 Not used: E:\arduino\libraries\MAX31850_OneWire

Unfortunately if you're using Arduino IDE 1.8.10 and you have spaces in the path where the libraries are installed, you might find that the paths are cut off. This is caused by a bug in the Arduino IDE 1.8.10:

If it causes you problems, you can use Arduino IDE 1.8.9:

snaudi:
How can I clearly define which library shout be used by the Compiler?

There is not really a great way to do this. The simplest solution is to delete all but the library you want to be used. Especially with the case of OneWire 2.3.5 and 2.3.3, I can't imagine why you'd want both of those installed. In the case of the OneWire and the MAX31850_OneWire library, it might make sense though.

When multiple libraries are found that match an #include directive in your code, the Arduino IDE tries to be smart about deciding which is the correct library to use. The decision is based on multiple factors:

  • Architecture match between the board (as determined by the architecture folder name of its hardware package) and the library (as determined by the architectures field in library.properties). Explicit match > wildcard match > mismatch. If a library has no library.properties or no architectures field in library.properties, that is considered a wildcard architecture match.
  • Filename/folder name match. If the library folder name matches (or comes close to matching) the filename in the #include directive, that library is given preference.
  • Library location. {sketchbook folder}/libraries > {hardware package folder}/libraries > {Arduino IDE installation folder}/libraries

Libraries bundled with hardware packages other than the one for the board you are compiling for are ignored so they don't even come into the equation.

All else the same, I would expect the IDE to prefer the OneWire library for OneWire.h. But let's say you actually wanted to force it to use the MAX31850_OneWire. The best solution then is to add an #include directive for a .h file that is unique to the library you want before the #include directive for OneWire.h. I would guess that the MAX31850_OneWire library has a file named something like MAX31850_OneWire.h already.