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"
Not used: /Users/andrewh/Library/Arduino15/packages/m5stack/hardware/esp32/1.0.7/libraries/SD
Here are two Band-Aids you can use.
You can rename one of the libraries then there won't be a conflict.
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.
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.
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.
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.