I use C++ libraries in multiple Arduino and RedBear Duo projects without the need for copying library source code (both done using Arduino IDE). I want to use these libraries in multiple Photon projects now. For Photon, I’m using Particle CLI for compile. These are private libraries that won’t be “cloud published”, possibly not even “cloud contributed”, and the contribute step seems like it would fork the library source anyway, preventing reuse in Arduino IDE projects. Keeping the libraries local and using Particle CLI build seems practical, where only the final firmware is uploaded.
The Issue? How to single-source these local libraries across multiple Photon projects. Initial “success” in using these libraries on the Photon required copying library source code into each Photon project folder, like this:
/MyProj1/src/MyProj1.ino
/MyProj1/lib/MyLib1/src/.cpp <-- copy of original source from MyLib1
/MyProj1/lib/MyLib1/src/.h
/MyProj1/lib/MyLib2/src/.cpp <-- more copy of source from MyLib2
/MyProj1/lib/MyLib2/src/.h
/MyProj1/lib/MyLib3/src/.cpp <-- and more copies again
/MyProj1/lib/MyLib3/src/.h
/MyProj2/src/MyProj2.ino
/MyProj2/lib/MyLib1/src/.cpp <-- another copy of source from MyLib1 in another project
/MyProj2/lib/MyLib1/src/.h
Many libs, many projects, many copies. I call “particle compile photon” from within \MyProj1 and \MyProj2, and each project successfully compiles. The libraries even depend on other libraries, and it all works. But it’s no longer a single-source library: copies of library source code were needed under each project subtree.
How can I accomplish something like this:
/MyProj1/src/MyProj1.ino
/MyProj2/src/MyProj2.ino
/MyLibs/MyLib1/src/.cpp <— library source is kept in ONE PLACE
/MyLibs/MyLib1/src/.h
/MyLibs/MyLib2/src/.cpp
/MyLibs/MyLib2/src/.h
/MyLibs/MyLib3/src/.cpp
/MyLibs/MyLib3/src/.h
I began to consider explicit paths for includes, use of “no preprocessor” or “no compatibility” pragmas, looking into project.properties for explicit path definitions, etc, but I still don’t see how the compiler and linker will know what folder to pick up for these libs. I’ve been searching on this issue, probably missing something right in front of my nose…
Any pointers on reusing a common set of library source code in multiple Photon projects via Particle CLI? Is this a solved problem?
–Don