Library.json - Relativ Path for Dependencies

Hi all,
I am quite new to PlatformIo and did not find and answer for the following situation: I have created a set of libraries. I keep them in one big library folder lib_folder. Within those libraries I have dependencies between them:
|-- LibA (e.g. dependent to LibB)
|-- LibB
|-- LibC
|-- …
Therefore, I wanted to connect them in the library.json with the dependencies flag. E.g. let’s say LibA is dependent to LibB. Absolut paths are working fine, but in my case I want to use relativ paths for sharing the libs locally to others. It would be nice if someone can just execute ‘pio pkg install –l absolute\path\to\Lib_A’ and with a relative path (‘./…/LibB’) in the library.json LibB is found. I tried to add the dependencies with relative paths but I was not able to make it work. I also tried to use the Directories commands, but I did not find a way to make it work. Maybe you have some input here. Thank you!


The use of relative paths is possible. However, these are relative to the current project!

Assume the following structure: There is a folder “projects”.
In this folder there is a subfolder “libStorage” and subfolders for the individual projects:

|  |--LibA
|  |  |--src
|  |  |  |-LibA.h
|  |  |  |-LibA.cpp
|  |  |-library.json
|  |
|  |--LibB
|     |--src
|     |  |-LibB.h
|     |  |-LibB.cpp
|     |-library.json
|     |--.pio
|     |--.vscode
|     |--include
|     |--lib
|     |--src
|     |  |-main.cpp
|     |-platformio.ini
|     |...

You can install the LibA library with the command pio pkg install -l ../libStorage/LibA.
The dependent library LibB will be installed automatically with the following library.json:

  "name": "LibA",
  "version": "0.0.1",
  "dependencies": [
      "name": "LibB",
      "version": "file://../libStorage/LibB"


  "name": "LibB", 
  "version": "0.0.1"
1 Like

Thank you for your reply! This seems to work. Do you know if there is any other chance to use a relative path to a library? The xx_DIR environment variables can only be used in the .ini right?

Unfortunately, I don’t know. What other possibilities are you thinking of?

Relative always means that it is relative to a certain starting point. This starting point will probably always be the LDF, which in turn is relative to the current project.

I have never used environment variables. As I understand it, they can be used to specify certain settings for the project outside of platformio.ini.

I assume you want to use them for libraries. That doesn’t make sense to me though.

Why don’t you just host your libraries on GitHub, for example?
This would solve all problems and is not bound to a special local folder structure.

True, I just wondered if you can make a define to the Lib Path and take every lib relativ from there.

  |-- LibA
  |-- LibB

LIB_DIR = absolut/path/to/Lib/folder //lib folder standard path

LibA library.json dependency:
"version": "file://./LibB"

But it seems that this is not supported for now.

Right, GitHub would be the easiest solution, but due to several reasons this is not working (at least for now).

Thank you for your help! This was really helpfull.