I've been using Arduino pretty problem free for years but this one has me stumped.
I got the M5stack Core2 because it seemed like a great prototyping device. I'm just trying to set it up and I keep getting an issue with a library conflict. Instead of using the M5 library the Arduino is using the built in Arduino library. How do I force it to use the right one?
Here's the error:
Multiple libraries were found for "SD.h"
Used: /Applications/Arduino.app/Contents/Java/libraries/SD
Not used: /Users/andrewh/Library/Arduino15/packages/m5stack/hardware/esp32/1.0.7/libraries/SD
I'm not familiar with this m5stack boards package. Please share the URL you added to the Arduino IDE's File > Preferences > Additional Boards Manager URLs field in order to install it.
Here are two Band-Aids you can use.
You can rename one of the libraries then there won't be a conflict.
or
When you include the library, use the complete path to the desired library, in quotes. (I am just guessing the library name): # include /Users/andrewh/Library/Arduino15/packages/m5stack/hardware/esp32/1.0.7/libraries/SD/sdlib.h"
Note, that is all on one line.
Both "fixes" work for the immediate issue, but if you update the library or the IDE, your code may not compile.
This one would only work for a header-only library. The source files of the library aren't compiled when you do this, meaning that most libraries won't work.
Yeah I tried the link in quotes and it didn't work. Arduino said it couldn't find it. I found a solution that I don't love. I'll post it in the main thread for others.
Here's what I did to fix it. Well to compile at least I don't know if this will actually work to access the SD. The wasn't actually part of my project I assume all the libraries get loaded even if you aren't using them.
The solution that worked for me:
Sketch -> Include Library -> Contributed Libraries -> SD(esp32)
Note insert this before the main library: #include <M5Core2.h>
What you will get is the following: #include <sd_defines.h> #include <sd_diskio.h> #include <SD.h>
The reason I'm not sure if this is the correct is I already have a esp board installed so the library may be for that.
I wish Arduino had a better way to manage libraries . Like a way to group them for projects.
One way might be to have several portable installs; I have just started experimenting with that. One portable install for AVR and one portable install for Wemos D1.
The changed behavior between Arduino IDE 1.8.13 and 1.8.14 regarding which of the libraries is picked is caused by this:
When there are multiple libraries that match an #include directive, the Arduino CLI (which is the engine under the hood of the Arduino IDE's GUI) must decide which of the libraries to chose. Previously, it did this according to the priorities documented on this now outdated page:
You can see that the factors in picking the library were:
How well the library's list of compatible architectures matches the selected board's architecture
How well the library's installation folder name matches the file name in the #include directive.
The location the library is installed at.
The m5stack SD library's architecture is a better match for the board than the SD library bundled with the Arduino IDE. So it wins this comparison, but only barely because they are both compatible (esp32 vs *).
The m5stack library's installation folder name is a perfect match for the #include filename, but so is the IDE's library, so this comparison is a tie.
So, in Arduino IDE 1.8.13 and previous, the "architecture optimization" of the m5stack library caused it to get higher priority.
and the name value of the library bundled with the IDE:
name=SD
So this flipped the priorities. Now the IDE library, which was never intended to be used by m5stack boards, is getting priority over the one that was written specifically for the ESP32 architecture!
Thanks to your report, I was able to report this issue to the Arduino IDE developers:
They are working on making a new 1.8.15 release of the Arduino IDE now. So if you don't feel like making the fix I described above, it shouldn't be too long to wait until a new version of the IDE becomes available that will work as you want it to without any modifications.
Hi @aso1101 I'm going to ask you to provide some additional information that will allow me to provide specific instructions for fixing this error.
Please do this:
Select File > Preferences from the Arduino IDE's menus.
Check the box next to "Show verbose output during: [ ] compilation".
Click the OK button.
Select Sketch > Verify/Compile from the Arduino IDE's menus.
After the compilation fails you'll see a button on the right side of the orange bar Copy error messages. Click that button. This copies the full output to the clipboard.
Open a forum reply here by clicking the Reply button.
Click the </> icon on the post composer toolbar. This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V. This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.