Library conflict! Don't know how to resolve

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

Any suggestions on how to manage this?

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.

Just delete both files, and try to download them again. That is how I fixed my problem like this one.

Here is the board link:
https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

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.

Thanks. That was very helpful. Just when I think I know all of them, another one is discovered!

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.

But Improved lib detection: check for matching name in library.properties by cmaglie · Pull Request #1276 · arduino/arduino-cli · GitHub introduced a new factor into the decision process: How well the name value in the library's metadata matches the file name in the #include directive. The name value of the m5stack library is:

name=SD(esp32)

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!

Thank you this is very useful information. Is there anything I can do to ensure the correct library is installed?

You can do this:

  1. Open /Users/andrewh/Library/Arduino15/packages/m5stack/hardware/esp32/1.0.7/libraries/SD/library.properties in a text editor.
  2. Change this line:
    name=SD(esp32)
    
    to:
    name=SD
    
  3. Save the file.

After that change, the correct library will be selected by the Arduino IDE.

Another option is to use Arduino IDE 1.8.13 (the issue is specific to Arduino IDE 1.8.14). You can download it here:
https://www.arduino.cc/en/Main/OldSoftwareReleases#previous

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:

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Check the box next to "Show verbose output during: [ ] compilation".
  3. Click the OK button.
  4. Select Sketch > Verify/Compile from the Arduino IDE's menus.
  5. 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.
  6. Open a forum reply here by clicking the Reply button.
  7. 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.
    Code block
  8. Press Ctrl+V. This will paste the compilation output into the code block.
  9. Move the cursor outside of the code tags before you add any additional text to your reply.
  10. Click the Reply button to post the output.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.