Libraries and Dependencies

When I add code that has library dependencies, like "WebServer.h," how can I tell which library that came from? I've searched in the Libraries utility that's part of the IDE, online, and in GitHub, and I've found numerous libraries that use a WebServer utility. I've even drilled down through various libraries to find methods that I'm looking for. This takes time and I was wondering if there is a simple way to discover a library without spending so much time chasing it down. I must be missing something.

do you have it defined as <WebServer.h> or "WebServer.h"

#include <WebServer.h> is how it was defined in the code I popped in.

Do the following in the Arduino online editor:

  • to the left side, find and click on the "Library" section
  • search webserver,
  • find one of these two,
    image

and modify it, whichever one has <WebServer.h> is the correct one, and of both have it just choose one.

actually scrap that, ima find the base, for you

Official Library

Enable "verbose output during compilation" (file → preferences in the IDE and analyse the output that it gives you.

The grep program is your friend (under Windows I use grepWin).

Yes, that's the library I'm looking at in GitHub, and I grabbed it and stuck in in the libraries folder. However during compile, it had dependencies beyond that library which are found elsewhere in that repository. Perhaps I need to figure out how to install everything from that repository to get the the dependencies satisfied.

Okay, Figured it out. I had to install via the link in the boards manager, following these instructions:
https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html

So, beyond this exercise, which took a fair bit of mucking around to find the GitHub repo, is there an easier way to ID a particular library from a simple include?

Mainly just searching the name.h on the internet, or looking through the Library Manager form the Online IDE

Yes, that's what I've been doing. I just seems such a hit and miss way to do things. Thanks for your help.

As @sterretje already explained, it is shown in the verbose compilation output. I'll provide more detailed instructions in case you didn't understand:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the "OK" button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to finish.

Now examine the contents of the black "Output" panel at the bottom of the Arduino IDE window. You will need to scroll up to see all the output. You will see something like this:

Alternatives for WebServer.h: [WebServer@2.0.0]
ResolveLibrary(WebServer.h)
  -> candidates: [WebServer@2.0.0]

One of the steps in the Arduino sketch build process is "library discovery". This is where, for each #include directive in the sketch and in its library dependencies, the build system searches the various folders where libraries are installed for all the libraries that contain a file in the root source folder with name matching the #include directive. The "candidates" line shows the list of libraries that were discovered for that header file.

Now look at the end of the output. You will see something like this:

Using library WebServer at version 2.0.0 in folder: C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\WebServer 

This tells you two things:

  • Which of the "candidate" libraries was selected by the build system
  • The path of that library on your computer

In this particular case the library name happens to match the header file name so it might seem pointless to look at those first lines. However, there is no guarantee that the library name will always match or even resemble the header filename.

Things are pretty straightforward in this case because I happened to only have one library installed on my computer that contained a WebServer.h file, but in other cases you will find that there are multiple "candidate" libraries.

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