Self Contained (i.e. Atomic) Sketch

brtaylor

Well-known member
I have a sketch that depends on several libraries. Instead of using the libraries in my "Arduino/libraries" folder, I would like to use local copies instead. The purpose is to enable me to freeze the library versions for this project, along with any necessary modifications, and keep the latest versions in the "Arduino/libraries" folder for general testing and prototyping. I've read suggestions of creating a folder in the sketch and putting the libraries in there, i.e.

Code:
test.ino
/lib
/lib/SdFat
/lib/mpu6500

However, this requires changing the path for my includes to point at the local folder. Also for any libraries that depend on other libraries, I need to change their path as well. Is there a better approach?
 
BrTaylor:
I solved this problem a long time ago.
At first I was using Apple's Xcode with EmbedXcode plugin which enabled me to be selective about what I want built. It had a builtin folder where you could put everything for the build of the program you were creating. You could refer to your user folder with all the Arduino add ons if you wanted to, or you could be selective about which Arduino add ons you wanted to use.
However after the demise of EmbedXcode plugin for Xcode I switched to Visual Studio with the PlatformIO plugin and guess what, it is exactly the same type of layout that Xcode used. I just drop all the libraries I want to use in the lib folder and Shezam I now have all the frozen libraries in the project folder so the code should always build.

If you want to use those libraries in your users Arduino folder instead all you have to do is refer to them as dependencies in the platform.ini file this this:
lib_extra_dirs = ~/Documents/Arduino/libraries

or you can refer to them independently from their online GitHub page like this:

lib_deps =
# RECOMMENDED
# Accept new functionality in a backwards compatible manner and patches
adafruit/Adafruit BusIO @ ^1.9.0

# Accept only backwards compatible bug fixes
# (any version with the same major and minor versions, and an equal or greater patch version)
adafruit/Adafruit BusIO @ ~1.9.0

# The exact version
adafruit/Adafruit BusIO @ 1.9.0

Now I have complete control of which versions of which libraries get built and installed with my program.

Of course this IDE behavior is what I have been accustomed to using in all the IDE's I have used since the late 1970's.

Regards,
Ed
 
"atomic" means something very different in programming.

I think you should be able to use
#include "foo.h"
rather than
#include <foo.h>
to pick up local versions first. Certainly that's the intention of the different syntaxes for #include.
 
@Ed, seems like I should learn PlatformIO then.

"atomic" means something very different in programming.

I think you should be able to use
#include "foo.h"
rather than
#include <foo.h>
to pick up local versions first. Certainly that's the intention of the different syntaxes for #include.

The issue is I would then need to plop all of my library source files directly into the sketch and hope those libraries also use the same scheme. I was hoping that I could just make a local lib folder as a sub-directory in my sketch and "just have it work", but that doesn't seem available with the Arduino IDE.
 
I think you should be able to use
#include "foo.h"
rather than
#include <foo.h>
to pick up local versions first. Certainly that's the intention of the different syntaxes for #include.
Yes, that's what I read on the internet as well.
However, when I copied a complete library folder to a sketch folder and changed the #include <somelib.h> to #include "somelib.h", the compiler did not use the local library [as shown in the compiler verbose output window].
Using Arduino 1.8.19.

Paul

edit: it does not seem possible to have local libraries, see this Github issue: Add the ability to find libraries in sketch folder. #11110
 
Last edited:
Use a “portable” install of the IDE? A bit hungry on disc space (1 or 2GiB) but ensures you have a consistent toolchain as well as libraries.
 
@Ed, seems like I should learn PlatformIO then.



The issue is I would then need to plop all of my library source files directly into the sketch and hope those libraries also use the same scheme. I was hoping that I could just make a local lib folder as a sub-directory in my sketch and "just have it work", but that doesn't seem available with the Arduino IDE.

Brtaylor:
If you need help do not hesitate to ask, either here or if you prefer private email associated with this account on the forum.

There are a bunch of videos on youtube about using PlatformIO also.

Regards,
Ed
 
Back
Top