My program for the RTL8720DN(BW16) compiles correctly on Arduino IDE 18.15, but does not when using Ardino IDE 2.0. It uses the Arduino Wifi Library even though I believe the library priority says it should use the board library.
The error is:
int _EXFUN(isxdigit,(int __c));
^
c:\users\mgsec\appdata\local\arduino15\packages\realtek\tools\ameba_d_asdk_toolchain\1.0.1\arm-none-eabi\include\ctype.h:23:5: error: expected ')' before 'int'
Multiple libraries were found for "WiFi.h"
Used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\mgsec\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.1\libraries\WiFi
Compilation error: exit status 1}
Hi @mgsecord . The reason is explained here:
opened 02:09PM - 14 May 21 UTC
closed 02:22AM - 07 Mar 22 UTC
conclusion: resolved
topic: code
type: imperfection
https://github.com/arduino/arduino-cli/pull/1276 added a nice new "Library Name … Priority" feature where the library dependency system uses the similarity of [the library `name` value](https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format) and the filename of an `#include` directive as one of [the factors](https://arduino.github.io/arduino-cli/dev/sketch-build-process/#dependency-resolution) in deciding which library to use when multiple matching matching libraries are installed. This was released with [Arduino CLI 0.18.2](https://github.com/arduino/arduino-cli/releases/tag/0.18.2) (and the [Arduino IDE 1.8.14](https://github.com/arduino/Arduino/releases/tag/1.8.14) and [2.0.0-beta.6](https://github.com/arduino/arduino-ide/releases/tag/2.0.0-beta.6) releases which use it).
Unfortunately, this change resulted in some [platform bundled libraries](https://arduino.github.io/arduino-cli/latest/platform-specification/#platform-bundled-libraries) which had previously been correctly correctly chosen no longer being given priority over the general purpose libraries from Arduino Library Manager.
An example:
```
$ arduino-cli version
arduino-cli.exe alpha Version: 0.18.2 Commit: 7b5a22a4 Date: 2021-05-10T14:30:17Z
$ arduino-cli lib install SD
$ arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
$ arduino-cli core install esp32:esp32 --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
$ mkdir /tmp/FooSketch
$ printf "#include <SD.h>\nvoid setup(){}\nvoid loop(){}" > /tmp/FooSketch/FooSketch.ino
$ arduino-cli compile --fqbn esp32:esp32:esp32 /tmp/FooSketch
In file included from C:\Users\per\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:26:0,
from C:\Users\per\Documents\Arduino\libraries\SD\src/utility/SdFat.h:29,
from C:\Users\per\Documents\Arduino\libraries\SD\src/SD.h:20,
from C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:1:
C:\Users\per\Documents\Arduino\libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.
^
Multiple libraries were found for "SD.h"
Used: C:\Users\per\Documents\Arduino\libraries\SD
Not used: C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SD
Error during build: exit status 1
```
You can see that the `esp32:esp32` platform's bundled library, which is written specifically for ESP32 architecture, was not chosen, contrary to the expected behavior. The reason can be seen in the library's [`library.properties`](https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format) metadata file here:
https://github.com/espressif/arduino-esp32/blob/1.0.6/libraries/SD/library.properties#L1
```
name=SD(esp32)
```
While the general purpose library's metadata is a perfect match for the `SD.h` file of the `#include` directive:
https://github.com/arduino-libraries/SD/blob/1.2.4/library.properties#L1
```
name=SD
```
The reason the names of some platform bundled libraries have these suffixes is to workaround a bug which caused libraries to be considered perpetually updatable by the the Arduino IDE's Library Manager when they had the same name as the platform bundled library:
https://github.com/arduino/Arduino/issues/4189
This bug was fixed in [Arduino IDE 1.8.6](https://github.com/arduino/Arduino/commit/ac6d3c1afffd81d429498b9d00bc2c92f849cbfe), ~3 years ago, but there was never a reason for the platform authors to change them back to their proper values.
Once this unexpected state of affairs was revealed, it was decided that the best approach would be to revert the change (https://github.com/arduino/arduino-cli/pull/1290) and make [a 0.18.3 release of Arduino CLI](https://github.com/arduino/arduino-cli/releases/tag/0.18.3) (accompanied by Arduino IDE 1.8.15 and 2.0.0-beta.7) in order to allow time for the maintainers of affected projects to prepare. [The "Library Name Priority" feature](https://github.com/arduino/arduino-cli/pull/1276) will be added back in the next release of Arduino CLI and the IDEs. In order to ensure platform bundled libraries get the correct priority, the only necessary change is simply to change the library.properties `name` values to match the primary header file after any spaces have been replaced by `_`:
```diff
--- a/library.properties
+++ b/library.properties
@@ -1,4 +1,4 @@
-name=SD(esp32)
+name=SD
version=1.0.5
author=Arduino, SparkFun
maintainer=Arduino <info@arduino.cc>
```
Standalone libraries should not be affected by this feature because the Library Manager installation folder name is determined by the `name` value, and thus their dependency resolution priority was already dependent on the name.
An additional "Library Name Priority" factor has been added since the version of the classic Arduino IDE you were using. This new factor changes which of the two libraries gets priority.
The reason is that the name value in the metadata file of the library bundled with the "AmebaD ARM (32-bits) Boards" platform is "AmebaWiFi":
name=AmebaWiFi
version=1.0.0
author=Realtek
maintainer=Realtek <ameba.arduino@gmail.com>
sentence=Enables network connection (local and Internet).
paragraph=With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi.
category=Communication
url=http://www.amebaiot.com/ameba-arduino-peripherals-examples/
architectures=AmebaD
whereas the value in the standalone library is "WiFi" . So it gets a perfect library name match priority to the #include directive for WiFi.h.
The fix is to change the library name to give a perfect match, which will cause it to tie with the standalone "WiFi" library for "Library Name Priority". After that, the "Architecture Priority" will cause it to get a higher priority.
Open this file in a text editor:C:\Users\mgsec\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.1\libraries\WiFi\library.properties
Change this line:name=AmebaWiFi
to this:name=WiFi
Save the file.
Now try compiling your sketch again.
Thank you @ ptillisch! That worked.
You are welcome. I'm glad to hear it is working now.
I submitted a fix to the "AmebaD ARM (32-bits) Boards" platform so that the manual patch I described above will not be necessary with future releases:
ambiot:dev ← per1234:optimal-library-name
opened 06:41AM - 28 Dec 21 UTC
When multiple libraries contain files matching an `#include` directive in the pr… ogram, the Arduino build system must pick one to use for compilation. Multiple factors are used in order to make an intelligent determination of which library is best, as documented [here](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#dependency-resolution).
In order to enhance this determination, the closeness of match between [the library.properties `name` value](https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format) and the filename in the `#include` directive is being added as one of those factors. This new factor is referred to as [**"Library Name Priority"**](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#library-name-priority). This change has been made in Arduino CLI [0.19.0](https://github.com/arduino/arduino-cli/releases/tag/0.19.0) (https://github.com/arduino/arduino-cli/pull/1300), and Arduino IDE 2.0.0-beta.12 and newer.
Unfortunately, this change can result in [platform bundled libraries](https://arduino.github.io/arduino-cli/latest/platform-specification/#platform-bundled-libraries) which had previously been correctly correctly chosen
no longer being given priority over their equivalent standalone libraries, which may be incompatible or not optimized for the platform's boards.
This priority inversion only occurs when all the following conditions are true:
- There is a standalone library installed which provides a header filename collision.
- The platform bundled library is architecture optimized (e.g., `architectures=AmebaD`).
- The standalone library is architecture compatible (`architectures=*`).
- The standalone library has equal ["Folder Name Priority"](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#folder-name-priority).
- The standalone library has better ["Library Name Priority"](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#library-name-priority) (e.g., `name=WiFi` vs `name=AmebaWiFi` for a library with primary header file `WiFi.h`.
The fix is to simply give the platform bundled library a perfect ["Library Name Priority"](https://arduino.github.io/arduino-cli/latest/sketch-build-process/#library-name-priority), as provided by the change in this PR.
Some platform bundled libraries were given a modified name as a workaround to [a bug](https://github.com/arduino/Arduino/issues/4189) in the Arduino IDE's Library Manager which caused Library Manager to always show the library as updatable under specific circumstances. That bug was fixed in [Arduino IDE 1.8.6](https://github.com/arduino/Arduino/commit/ac6d3c1afffd81d429498b9d00bc2c92f849cbfe), ~3 years ago.
For more information or discussion regarding this change, please see https://github.com/arduino/arduino-cli/issues/1292