How do I manage libraries properly for each project

Hello,

I am developing a project that has dependencies with multiple libraries. This project has different branches and versions, so sometimes I need to change or create new functions in my own libraries or even include new external ones.

My question is, is there a way I can attach my libraries to a sketch? Just like is done in Python with venv? I don't want to have all my libraries at Arduino/libraries, I would like to have them in a folder with the .ino file.

I think this is somehow achieved with PlatformIO, I am not sure about it, but in the project folder I can see a /include and /lib folders where the libraries are found.

Anyway, I normally use VSCode for programming and Arduino to load code to the microcontroller.

Thanl you so much for your time,
Diego

If you put the library files in the same folder as the sketch then use #include "libraryName.h" then the sketch will use the local library

1 Like

Just put them in the folder with the .ino file.
And include like this:

#include "MyLibrary.h"  // include library in sketch folder

#include <OtherLibrary.h>  //vs  include library in library folder
1 Like

You have been shown how to do what you ask, but isn't it defeating the purpose of having a library in the first place?

Ask me how I know having eleventeen versions of almost the same code sprinkled all over the projects in the Arduino sketches folder is a nightmare.

Just sayin'.

a7

Unfortunately, there are libraries that depend on specific versions of other libraries or they won't work properly. This is about the only way to work around that problem.

Also, when shipping source code for someone else to build, having different library versions is a common source of trouble. Much easier to zip up everything together and do it that way.

1 Like

Yes. You can need to go as far as zipping up the entire tool chain. Legacy projects can be a real pain.

You might even maintain a machine that has it all RTG. No OS updates allowed, no updates to anything.

If, however, I were to zip up my project files, and cared enough to be sure to also provide the libraries they used, I would add the libraries and expect of any user that they install, and use, those libraries as libraries.

Not as tabs added to my project file.

a7

TBH, I actually considered this for a project a year ago where it worked perfectly on my desk but the client in another country couldn't get it to work.

Just a week ago after a number of units of a project I shipped needed a minor fix and I was thinking about that again. Happily I figured out a way to write a batch script to automatically program them from a precompiled binary so that particular disaster was averted.

I've made good use of the ability to maintain multiple portable IDE versions.

So that solves some problems, and if I grab a sketch I may have even left behind some indication of what IDE version it goes best with.

One has to envy people like chefs, who create products that have a very short life cycle.

a7

1 Like

For example, there are some projects (not exactly talking about arduino) where you can find a requirements.txt where the version of each library is found. That's exactly the problem I am facing, the fact that I have different project versions that use different libraries versions.

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