Specify library to use

Sometimes a sketch will not compile and the messages warn that several libraries are available for XXXXX.h. The IDE then goes on to say which library it has used and which one(s) it hasn't used, as shown below:

Mehrere Bibliotheken wurden für "BLEDevice.h" gefunden
Benutzt:~/Arduino/libraries/ArduinoBLE
Nicht benutzt:~/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE

Sometimes both libraries are required, for different boards for example. How can one specify which library the sketch should use. For instance in the example above the sketch is loading the wrong one.

An absolute path to the library.

Sometimes both libraries are required, for different boards for example

If this is something you really need, you could also look into an alternative IDE, like https://platformio.org/

How do I include an absolute path in the sketch? I tried the following but that would not compile.

#include <~/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE/BLEDevice.h>

#include <~/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE/BLEDevice.h>

Try #include "~/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE/src/BLEDevice.h" instead

Nope, still won't compile. I also tried replacing the "~" with "/home/stevesdirectory", ie the full path, without success.

Thanks @toddnz

@ledsyn Actually it isn't an absolute path but relative.

Did you notice the src directory at the end? Just a guess at something that might be missed.

Sorry, I do not understand what you are asking. What src directory at the end of what?

If this is still the case then absolute path is needed :upside_down_face:

Does this mean: no ~ ?

If you open the directory ~/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE in your file manager, I imagine there is a subfolder named "src".

When you give the absolute path, you need to remember the src subfolder.

Unfortunately no.. yes I mean.

So full path /home C:\Users etc

1 Like

In Linux systems it is shorhand for the path to the users directory. But as I wrote above I removed the "~" and wrote the full path but it still didn't compile.

In Linux full path = /home/username.

You're right, I didn't include that.

I'm thinking that with different libraries for different boards, that some compiler directives should work. I have very basic knowledge here, but perhaps something with #ifdev. There are sketches that will demonstrate this.

Yes indeed! However after checking that the file BLEDevice.h was actually within the src directory I tried again with:

#include<"/home/stevesdirstory/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE/src/BLEDevice.h">

But is still won't compile with the warning that there is "No such file or directory" Possibly a access rights issue now.

Thank you so much for your patience. I have to ga away for a while now but if/when I get this fixed I will report here!

No <> , just " "

#include "/home/stevesdirstory/.arduino15/packages/m5stack/hardware/esp32/2.0.7/libraries/BLE/src/BLEDevice.h"

Good luck!

2 Likes

Great! That's it! Thank you for your patience.

1 Like

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