In simple terms, how to load a library so all projects can see it

Had two arduino projects and had to load the libraries in each. Is there a SIMPLE way to load a library so both projects would see them, the way arduino IDE does?

Sort of, yes. But it isn’t recommended. Global libraries are a thing of the past as they have caused numerous problems. However…

  • Create a folder, I’m assuming Windows, call it C:\pio_libs.
  • In C:\pio_libs, create a library folder for your common library.
  • You can create src and include in the new folder but not mandatory.
  • Copy your library’s source code into the library folder, or into src and include.
  • Edit platformio.ini and add lib_extra_dirs=c:\pio_libs.
  • Edit platformio.ini and remove the library name(s) from lib_deps=....
  • Edit the projects source code to ensure you have #include "library_header.h" as appropriate for the library.
  • Build.

lib_extra_dirs and folders beneath will be searched and used as required.



Thank you Norm

1 Like