Report library version(s) at runtime

I searched the internet and was not able to find any information on how I can report the version of the various libraries my sketch uses, at runtime. While debugging, I make use of Serial.println(). Is there a way to also output the version of libraries? I "figure" there has to be as the library manager knowns the available version. Is that information included in the compiled sketch? How would I access that information to output?

Thanks.

Hi @notahardwareguy

Welcome to the forum!

I am not sure how to do what you are asking, but for a workaround, I would check the library versions and add serial prints with the library versions. Then when you update them, change the serial prints.

The Library Manager knows which library versions are available and the compiler reports on which libraries are used if you set your preferences correctly, but the information will not be in the compiled code

Why would the library version used be included in the compiled sketch when memory is at such a premium and the information is if no use to the program ?

I could understand doing that under "normal" conditions but I was hoping that there was a flag or such that would allow that information to be included "on demand". Some way to write either code or directives to have that information included.

What problem are you trying to solve?

I want to verify the libraries used for a given build. Some of the libraries I use are not "standard" and I have had issues in the past where a library upgrade breaks things but don't have good documentation on the library versions used so, figured if I could get the working program to tell me what the library [in question] version is, I can better maintain my docs. My thinking is as I get the working version, have it show the library versions used, doc that, turn off the switch, update all libraries, recompile, and execute. If all is well, report and update doc again. if fail, can see which are different to try and debug and/or revert to known working versions.

I thought of that but was looking for something more "direct" where as the program told me what is was built with. I have "messed up" and not kept good records in the past so was trying to find something more fool [me] proof.

That makes sense. I just don't know if it is even possible.

You can have the Arduino IDE do that for you:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Check the checkbox next to "Show verbose output during: ☐ compilation".
  3. Click the OK button.
  4. Compile your sketch.

Now check the contents of the black output panel at the bottom of the Arduino IDE window. It will show all the libraries that were used by your sketch.

For example:

Using library Servo at version 1.1.8 in folder: C:\Users\asdf\Documents\Arduino\libraries\Servo 
Using library Adafruit_Circuit_Playground at version 1.11.3 in folder: E:\arduino\ide\arduino-1.8.19\libraries\Adafruit_Circuit_Playground 
Using library SPI at version 1.0 in folder: C:\Users\asdf\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SPI 
Using library Wire at version 1.0 in folder: C:\Users\asdf\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\Wire 

Now you need to document that information.

If you want to be even more precise in documenting the dependencies, also record the version of the boards platform you are using. In the example above, my sketch happened to be using the platform bundled libraries SPI and Wire, so the paths also show that I am using Arduino AVR Boards platform version 1.8.4. In other cases, your sketch might not be using any platform bundled libraries, but you can still find that information in the output, from a line that looks like this:

Using core 'arduino' from platform in folder: C:\Users\asdf\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

It might be of user to a human, though! That's why I want to see it, too.

Life is simple if you use portable installs for projects. Each project has its own portable install which includes everything that is needed (board package, libraries, source and so on).

If you update e.g. a library in project A, project B will not be affected.