How to use the lib directory in 0.6.0-rc1+

Continuing the discussion from Particle Firmware Update Thread:

How do we use this?

I assume this is meant for Particle Dev/Particle CLI users, who have been stuck with throwing everything into the same directory.

I looked into the commit assosicated with this enhancement and see that when you have a “src” directory, it then calls this an “extended” application environment; this includes the sibling “lib” directory and subfolders.

  • Does the .ino go in src/?
  • How do I #include the libs in lib from within my .ino?

Let’s say I want to use the Blynk library, located at lib/blynk/blynk.h.
Do I include by:

  • ../lib/blynk/blynk.h (relative to the .ino in src)
  • lib/blynk/blynk.h (relative to the project root)
  • blynk/blynk.h (like Particle Build, relative to the lib root)
  • something else?

I tried to play around with this since it’s something I’ve been looking forward to for a while, but can’t get any configuration to build within Particle Dev (haven’t tried CLI yet).

I believe I just answered my own question;

  • The *.ino and any non-vendored files go in $APP_ROOT/src
  • The vendored libraries go in $APP_ROOT/lib
  • To include a vendored library from your .ino, include it by the full path, with preceeding forward slash: #include "/lib/library/path/to/header.h"

This seems to compile from within Particle Dev. Finally, I can include libraries as Git submodules!

These are changes required for the new library system to easier import libs across all Particle IDEs and get closer to the pseudo standard set by Arduino IDE.

There will be a seperate announcment once “Libraries v2” goes live.

And it does get even better :wink:

I spoke too soon - this arrangement above compiles but produces a completely unusable binary. Am I missing something? Can I use this “feature” before you guys fully release the “Libraries v2” shenanigans?

I’d think this will only be usable once all the tools in the chain are adapted accordingly.

But I have no idea how far on Particle is with that.
Maybe @jvanier can give us a clue :wink:

I wonder what “0.6.0-libraries.1” firmware version is for?

The short answer is we’re working on supporting libraries with the CLI and Particle Dev as well as Build. All will be made clear soon :wink:

To include a vendored library like lib/neopixel from your .ino, you should only need to include the library name without path: #include "neopixel.h"