Lib_extra_dirs relative path

Hi PlatfromIO Community,

I have succesfully created a library named “common” with it’s library.json
I need to include this lib to multiple projects (test_project_a, test_project_b)

librairies/
└── common/
├── utils.hpp
├── utils.cpp
└── library.json

test_project_a/
├── platfromio.ini
└── src/
└── main.cpp

test_project_b/
├── platfromio.ini
└── src/
└── main.cpp

To each test project platfromio.ini I added the following lines and it’s working:
lib_extra_dirs = F:\my_absolute_path\librairies
lib_deps = common

but i would want to use a relative path to share the project with my team members:
lib_extra_dirs = …/librairies
lib_deps = common

Do you have some ideas to get this working ?

Thanks !

2 Likes

Are you on windows or linux? On my ubuntu it works with lib_extra_dirs = …/lib, try using …\libraries.
Or try changing your libraries structure to
librairies/
└── common/
└──utils/
├── utils.hpp
├── utils.cpp
└── library.json

Sorry for formating can’t find how to put tabs. What I mean is try putting utils.c and .h into separate folder utils.

Thanks for the help,

I made a mistake on the first post about the libraries folder structure, the correct one is:

librairies/
└── common/
    ├── utils.hpp
    ├── utils.cpp
    └── library.json

test_project_a/
    ├── platfromio.ini
    └── src/
        └── main.cpp

test_project_b/
    ├── platfromio.ini
    └── src/
        └── main.cpp

I tried the following without success:
lib_extra_dirs = F:\my_absolute_path\librairies ;working
lib_extra_dirs = …\librairies ;not working
lib_extra_dirs = …/librairies ;not working

I’m on win10.

As the relative path is not working, maybe another solution would be using dynamic variables
Something like this is in the example on the dynamic variables pages but i can’t find a variable for current project folder like:
lib_extra_dirs = ${current_project_folder}..\libraries

Also, by looking at this thread

I tried the following without succes:

lib_extra_dirs = ..\..\librairies

I also tried putting my library “common” in my project lib/ folder, everything is working correctly in this case.

Further informations:

case 1
lib_extra_dirs = F:\my_path\librairies

LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <common> 0.0.0
...
SUCCESS

case 2
lib_extra_dirs = …\librairies ;same result with …/librairies
lib_deps = common

LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <common>
...
src\main.cpp:1:10: fatal error: utils/Utils.hpp: No such file or directory
FAILED

case 3
lib_extra_dirs = …\librairies ;same result with …/…/librairies
lib_deps = common

LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <common>
...
src\main.cpp:1:10: fatal error: utils/Utils.hpp: No such file or directory
FAILED

here is for reference my library.json

{
	"frameworks": "mbed",
	"name": "common",
	"platforms": "*",
	"version": "0.0.0"
}

Yay i finally found it by accident on this page :smile:

All is now working with:
lib_extra_dirs = ${PROJECT_DIR}\..\librairies

2 Likes

Huh I missed the page with all built in variables on the doc when i was searching for them, it was here

https://docs.platformio.org/en/latest/projectconf/section_env_build.html#built-in-variables

1 Like