Two versions of 'same' library installed?

Is there some way to have two versions of the same library installed, distinguished of course by different names, such as a version suffix?

I'd have found this useful on several occasions, but the following is the one that prompted my post.

I have version 4.3.3, the latest, of 'IRremote' in IDE 1.8.19's Manage Libraries. That works for many sketches. But others fail because they were written years ago using version 2.x. There have been significant changes to the library since then. (Coinciding I think with its development and maintenance changing from Ken Shiriff to Armin Joachimsmeyer.)

Rather than having to downgrade/upgrade each time depending on the sketch, it would be good to just use the appropriate #include statement. In this case either
#include <IRremote.h>
for the current version, or
#include <IRremote_201.h>
for the version known to work with old sketches.

BTW, why does the github page accessed by using 'more info' from Manage Libraries for 'IRremote' risk ambiguity by heading it
'Arduino-IRremote'?

Easy:

  1. Install old version.
  2. Rename library directory from IRremote to IRremote_<version>
  3. Edit library.properties
    • Change name to IRremote_<version>. This will stop the IDE from touching this version when updating IRremote.
    • Optionally update option and paragraph to indicate that it is an old version for old sketches.
  4. Add src/IRremote_<version>.h
/**
 * @file IRremote_<version>.h
 * @brief #include this file instead of IRremote.h in sketches that use version 2.x API
 */
#include "IRremote.h"
  1. Install new version.
1 Like

I thought the newest IRremote library file was named IRremote.hpp

The library is called ‘IRremote’. But for some sketches the familiar #include statement must apparently now be replaced with this new ‘.hpp’ file. A fuller explanation under Using the new *.hpp files here:

If there is a compiler directive preventing the same file being loaded multiple times, correct the name there as well.
Make sure you keep the different versions in different folders.

If a Header file is included in a sketch, all .cpp files in that same folder will also be included. (i think that's what happens)

I'm struggling a bit at that level. Haven't given up, but may well elect to downgrading each time needed, then updating afterwards. Simpler and less risky. :slightly_smiling_face:

Note correction: I believe the 'old' version should be 2.3.3, not 2.0.1.

If you have code that requires an old version of a library that will never change have you considered copying the library files to the sketch folder and explicitly #including the local version ?

No, but I'll follow up that suggestion, thanks.

What would be the 'local' version in the case discussed?

The local version is the library in the same folder as your .ino file

If you use this form of #include

#include "myLibrary.h"

then the compiler will search the sketch folder for it before searching the other library folder paths