I’m sorry if this is a duplicate post, but I haven’t been able to find the answer I’m looking for.
What I’m trying to achieve is to have a local c++ library, and use it in multiple projects. I don’t want to bother with git and publishing the library if possible since I will be the only one using it anyway. Is this possible? Or if not, is there something close to it?
With a file structure like this:
.
├── libraries
│ ├── LibA
│ │ ├── src
│ │ │ ├── LibA.cpp
│ │ │ └── LibA.h
│ │ └── library.json
│ └── LibB
│ ├── src
│ │ ├── LibB.cpp
│ │ └── LibB.h
│ └── library.json
└── projects
└── projectA
├── include
├── lib
├── src
│ └── main.cpp
├── test
└── platformio.ini
and the use of Local Folder and “Symbolic Link” feature you can include your libraries like this:
lib_deps =
symlink://../../libraries/LibA
symlink://../../libraries/LibB
So I’ve got this working for my simple libraries; however I also have some more complex libraries in which I inherit from a base class. Say LibParent contains the base class, and I have two libraries (LibChildA and LibChildB) that inherit from the parent class, now I’m getting include errors in the child classes.
lib_deps =
symlink://../../libraries/LibParent
symlink://../../libraries/LibChildA
symlink://../../libraries/LibChildB
So in LibChildA.h, the following is not possible: #include "LibParent.h"
My guess is I need to tell the child class that it needs to look in other libraries, so I added the following in the file LibChildA/library.json
, but it still won’t work. Am I doing the linking wrong?
"dependencies":
[
{
"name": "LibParent",
"version": "*"
}
],
Since a local folder such as ‘libraries’ on a hard disk is not a registry in the true sense of the word, a ‘dependency’ setting cannot help install the appropriate library automatically.
This won’t work because #include "LibParent.h"
will look in the same folder of the including file (LibChildA / LibChildB).
You have to use the “global include” : #include <LibParent.h>
Another way would be to put your private libraries into the lib
folder - See my answer in Private library not finding one of other private libraries