Library folder names, IRremote in particular

I have a number of sketches that were written for IRremote.h v 2.8.0 that no longer run on v4. Rather than change them all, I wondered if I could have both versions of IRremote installed. I wonder how I could do that, and how I would pick the right one in my #include statments.

But I noticed that currently IRremote.h is in a folder named "IRremote-2.8.0", and I wonder how the IDE (v1.8.8) knows to look there for it. Does anyone know how the IDE keeps track?

Also, by the way, does anyone know of a good tutorial on IRremote v4? I've been through the examples, but it's gotten a lot more complicated, and I'm having trouble understanding how to use it.

I'm not a programming expert, but I'll tell you what I think happens with Arduino libraries.

When you use a library, you refer to it in one of two ways:

Either #include <xxxxx.h> (<>) or #include "xxxxx.h" (" ").

In the first case, the IDE will look for the library in the library folder defined in
"Sketchbook Locations" in preferences in the IDE.

In the second case, the library files need to be in the same folder as yyyy.ino.

So if you want to use different libraries, change the define in your code and place the libraries in the project folders.

Programming experts can correct me where I'm wrong.

HTH

@ruilviana
<> is system
"" is local followed by system. Used to override a system declare


If you need to keep old versions of libraries rather than updating the sketch, you could place them in your libraries folder in a folder with a naming convention that makes sense to you. When you need to use those libraries, simply use the "" local nameing convention as in "IRemote280.h". So it will look like the following
#include "IRemote280.h"
And your libraries folder will look like the following

You will also need to modify the library.properties to change the version number there to a high 9.9.9 value so it does not auto-update.

It simply looks in every library folder for a file named IRremote.h.

In the case where you have multiple versions of the same library installed globally (under the sketchbook folder), the only way to control which of the libraries will be chosen by the library discovery system is to use a filename in the initial #include directive which is unique to the target library, as described by @sonofcy.

If you don't use a unique filename in the #include directive, then the library discovery system uses a well defined algorithm to decide which of the candidate libraries should be used:

https://arduino.github.io/arduino-cli/latest/sketch-build-process/#dependency-resolution

So given the same determining factors, the same library would always be chosen and thus you would not be able to control which of the multiple libraries would be used with a non-unique filename.

Rather than that, you can have multiple Portable Installations of IDE v.1.8.x on your computer. In each one you can control exactly which version of which libraries you have installed. You can also control the version of all board packages are installed. Your programs that need specific library and board package versions would be stored in the "sketchbook" directory of that portable installation.

Unfortunately, the Arduino development team has not seen fit to provide IDE 2.x with this capability. That's why I use a 3rd party IDE for serious code development.

@ShermanP I have a nagging doubt that if a certain library is now 'out of date', then there is a possibility that libraries that it depends on may also be 'out of date'. This means maintaining more than 1 'out of date' library.
I believe another option is to use Platform IO.

I should have said that in fact I am using the portable installation of the IDE. So the path to a sketch is:

C:\Arduino\Portable\sketchbook\irledDriver\

and the path to the last subfolder of the library is:

C:\Arduino\Portable\sketchbook\libraries\IRremote-2.8.0\src\private\

The src folder has 27 C++ files, including IRremote.h, plus two in private.

I would rather not use up drive space for a full extra copy of the IDE. But I'm not clear how I would put the library in the local sketch folder, assuming the IDE would look there first. Would the irledDriver sketch folder have a subfolder named "libraries" with the full IRremote library in it, or just the IRremote folder, or what? And would I need to use the full pathname of the library in the #incude statement, including "src"?

I recommend putting the library under the src subfolder of the sketch:

irledDriver/
├── irledDriver.ino
├── src/
│   └── IRremote/
│       ├── src/
│       │   ├── IRremote.h
│       │   ...
│       ...
...

The alternative would be to put the library files in the root of the sketch folder, but that gets messy.

You should use the relative path in the #include directives.

For example, if you had this #include directive when using the globally installed library:

#include <IRremote.h>

you would change it to this:

#include "src/IRremote/src/IRremote.h"

Thanks very much. Yes, that works perfectly. I moved the library folder into the sketch folder as you suggested, and it compiles perfectly. And then I deleted files that weren't necessary, such as the examples, the doxy file, etc., and it still works.

So now I can install the latest version of IRremote in the normal way, but use a local v2.8 copy for sketches that need it.

Can you clarify whether IDE v2 permits a portable installation by adding a "portable" folder? If not, is this being considered?

Arduino IDE 2.x is a complete rewrite of the Arduino IDE project, in a different programming language (TypeScript vs Java) and not sharing any code at all. So each of the features of Arduino IDE 1.x has to be implemented all over again by the Arduino IDE 2.x developers. Unfortunately they did not get around to implementing the portable feature.

The Arduino IDE developers are tracking the task of adding a portable capability here:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject: