How to share common code between projects?

I have been googling this for a while, but can’t find any answers that seem to fit my situation. However I found something that looked promising regarding setting up a lib_extra_dirs option in platformio.ini. But this option is depricated and I don’t know what to do as an alternative.

I have a bunch of projects (each is a sensor in a home automation system) that are quite similar and each use a few common functions that I have written. Currently each project has its own copy of these common fuctions. Not a good idea!

How do I setup a library of these functions so that all projects can access them? My folder structure is as follows…

main folder
     project A
     project B
     project C

I’m happy to change the folder structure if it is not ideal. In any case, where should I put the common source code and how will the compiler find it?


You can still have lib_deps (docs) in each project that point to common library folders via a symlink (so that no copy is done), e.g.,

lib_deps =

That would have previously been lib_extra_dirs = ../common_libs.

1 Like

Perfect, thanks Max.