Clarification on Nesting Libraries

IDE 1.4.0 | CLI 2.11.2

This is related to but not exactly the same issue as described in “Nested Libraries” topic. I am building a set of library objects for a robot we want to deploy in our classroom. They worked well in the standard Arduino setup but we are experimenting with different IDEs and noticed some interesting behavior with Platformio.

All the test programs have been modified (minor changes) to work in the Platformio IDE but we have noticed some a behavior wrt how both our own and built-in libraries are imported. Eventually we will deploy the library on Git but are still in development so the custom libraries live in the lib folder of our test suite. (If it matters: most of the classroom machines are Ubuntu 16.04 but there are a few MacOSX machines as well)

One clear example: we have customized I2C classes that read from specific hardware where the source code depends on the Wire.h library. Including the Wire.h library in our source is not sufficient to allow the test module to compile unless we also #include it in the test module as well. to wit:

main.cpp:

// Main.cpp which would correspond to the .ino file #include <Arduino.h> #include <PhysBotEncoder.h> ... void setup() { etc; }

void loop() { etc; }

PhysBotEncoder.cpp:

// PhysBotEncoder source file (the header doesn't // need the Wire.h declarations #include <Arduino.h> #include <PhysBotEncoder.h> #include <Wire.h> ... stuff; etc;

This arrangement will throw a message that Wire.h cannot be found. BUT if Wire.h is included in main.cpp then all is well. I have had similar issues with my own nested libraries which something described under the related post above but this is seems to happen with ‘built-in’ libraries as well.

I have tinkered with the ‘lib_ldf_mode’ setting and it doesn’t seem to change anything although I don’t think this works with the version I am playing with.

Is this expected behavior? Right now all our ‘custom libraries’ live in the lib folder of the main project. Each class declaration and source lives in its own folder. Can these be combined into one folder? I am just not clear on either the convention and the requirements on how to organize a complex project like this. I apologize if I missed something in the documentation. Thanks in advance for any assistance.

  1. Don’t test with PlatformIO 2.0. It has a lot of issues. We will not support it. PlatformIO 3.0 is full replacement for it. We will release PlatformIO 3.0 this week. It is a very big update to while PlatformIO ecosystem.
  2. Switch to PlatformIO 3.0 development version Redirecting...
  3. Move #include <Wire.h> from PhysBotEncoder.cpp to PhysBotEncoder.h. PlatformIO Library Dependency Finder will find all dependencies automatically. By default, it works in 1-st mode. See docs Library Dependency Finder (LDF) — PlatformIO latest documentation

Thank you, that was a big help. It works fine now. I am really liking this IDE.

Since I am putting together a test suite of projects built against the one set of library files I presume the best way to link against the common is to use the lib_dir construct in the platformio.ini file?
e.g.
[platformio]
lib_dir = …/commonlib/

as opposed to links to directories. (Eventually we will host the library on Git, when it is ready)

PlatformIO 3.0 and PlatformIO IDE 1.5.0 have been released! Please use Redirecting...