Selecting specific version of libraries

Hi,

I'm using arduino 1.8.19.

I have several old "arduino uno"-based projects who rely on a very old version of 'Adafruit_GFX' library, dated 2016.

I also have a few recent esp32-based projects who drive an SSD1306 oled display.
The Adafruit_SSD1306 library requires 'Adafruit_GFX' library to work.

If I leave in place the older GFX library, the esp32 project crashes while trying to initialize the SSD1306 display.

If I replace it with the latest GFX library, the esp32 project works fine.

Problem:
I can't compile the very old "arduino-uno" project with the newer GFX library because it exceeds the flash space by far.

Question:
Is there a way to leave both libraries in place and have each project select which one to use?

NOTE:
Just for the purpose of preventing automatic update from breaking compatibility with older projects, like it would have happened in this case, I manually manage some libraries, placing them into the sketchbook directory, keeping them safe from automatic updates.
Of course this does not apply to core-specific libraries.

In this specific case, the old and new GFX libraries have different folder names, like this:

old one: ./sketchbook_directory/libraries/Adafruit_GFX_old
new one: ./sketchbook_directory/libraries/Adafruit_GFX

Of course I can't leave them both in place.
When I compile an old 328 project I have to remove the 'Adafruit_GFX' folder and put in place the 'Adafruit_GFX_old' folder. Note that I don't need to rename it as it's correctly found by the linker anyway.

Vice-versa when I compile an esp32 project: I have to remove the 'Adafruit_GFX_old' folder and put in place the 'Adafruit_GFX' one.

Renaming the .h and .cpp files does not solve the problem because the GFX library is referenced by other Adafruit libraries (for example the oled SSD1306 library), so it's not just a matter of changing the #include in my project.

Is there any way to avoid having to manually swap the libraries every time I switch from a 328 project to a esp32 project?

Thanks a lot and Bes Regards
Alessandro

You can't do it with Arduino 1.x, as far I know.
But if you programmed Arduino with Platformio or MS Visual Studio VMMicro plugin - you can setup independent library set for each project

You could put the library files specific to a sketch in the same folder as the sketch and change #include <library.h> to #include "library.h" to force the sketch to use the local, specific library

Hello and thanks for the reply.

The problem with this approach may be that other libraries (such as 'Adafruit_SSD1306' rely on the 'Adafruit_GFX' library).

This might require modifying them all?

Thanks

Alessandro

Thanks, I'll consider that.

The whole process can get very tangled

To be honest you would be better off changing the old sketches to use the latest version of the library

He pointed out the code bloat in the new library exceeded the flash size.

So he did. I missed that

One answer would be to use a board with more memory than the Uno

For exactly this reason whenever I finish a project I do as @UKHeliBob suggests and place copies of all libraries used in the sketch folder so I eliminate any chance of updates messing up things if I ever return to that project.

On projects large enough, particularly ones that I do for others. I'll load the sketch with all needed libraries and a portable copy of the IDE onto a flash drive and hide it inside the project.

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