I’m trying to introduce a private folder for shared libraries across all projects using a lib_dir option in platformio.ini (and later PLATFORMIO_LIB_DIR env variable).
The problem is I cannot make it work:
- I have a complete compilable project with libraries in the regular /lib - it works OK
- I moved the lib subfolder above into another location, /home/user/shared, so that the final is /home/user/shared/lib - and there come subfolders with libraries.
- I declare in the platformio.ini file: lib_dir = /home/user/shared/lib and … the compiler does not see the libraries.
Is there a reason that lib_dir cannot contain the global path or am I missing something here?
Thanks in advance for any hints,
Piotr
Thanks,
I know this post but unfortunately it is not an option as I’m not willing to modify all Platformio.inis nor expose details for paths on the file system for the security reasons (it is a university compiler for students), so that I’m looking for a solution that uses global variable rather than editing each individual project.
Regards,
P.
Unlike in the ArudinoIDE, there is no global library directory in PlatformIO.
This would result in all libraries being included in the build process of the project, even if there are libaries which are not included / used by the project.
You must therefore specify the libraries to be used for each project using lib_deps
in platformio.ini
.
In the example linked above I showed a way to use relative paths… relative to the current project. There is no security leak in doing this.
IMHO the best way is to host your libraries on github. This also allows you versioning, which is not possible with libraries hosted locally.
Got it thanks. Using an external repo is an option to be considered. Still, I’m wondering what is the purpose of the lib_dep option in platformio.ini (and related global variable PLATFORMIO_LIB_DIR)?
Regards,
P.
Sorry, my mistake. It was just a typo. I meant:
Still, I’m wondering what the purpose of the lib_dir option in platformio.ini (and related global variable PLATFORMIO_LIB_DIR) is.
According to the documentation you pointed out, which I was already investigating, it should rebase the root library folder, which is where I started. Still, it doesn’t work (see my first post in the thread). So, what is this feature expected to do? The documentation is either wrong or very laconic.
As far as I can understand, this feature is supposed to rebase the library’s root folder for the project (if used in platformio.ini) or, per all projects, if used as an environmental variable, which is exactly what I’m looking for.
Regards,
P.
Afaik, this is just to “rename” the project’s default “lib” folder to another folder-name eg. “my-lib” or something like that. However, the folder must still be a subfolder of the project.
The environment variable PLATFORMIO_LIB_DIR
overrides the lib_dir
setting and can be used to set this for all your projects.
I think you got confused by the word “global” in this sentence from the documentation:
This option can also be configured by the global environment variable PLATFORMIO_LIB_DIR
.
But global here references to the environment variable, not to the library folder.
1 Like
What does work is the following scenario:
File structure:
.
├── libraries
│ └── LibA
│ ├── LibA.cpp
│ └── LibA.h
├── project1
| ├── include
| ├── lib
| ├── src
| │ └── main.cpp
| ├── test
| └── platformio.ini
├── project2
└── ...
In each project’s platformio.ini
:
[platformio]
lib_dir = ../libraries
or
set the global environment variable PLATFORMIO_LIB_DIR
set to “…/libraries”.
Warning: The latter will affect all projects!
But as written before: This is bad practice.
global_lib_dir has been marked as deprecated for a good reason.
Thanks.
Indeed, the word “global” is misleading here, so I was looking for a dummy solution to the problem described below.
I’ve made a workaround with an additional script run before compilation that copies needed libraries to the /lib/ as required, and it solves the problem for now.
— problem description in short —
BTW, that is a part of the EU project I work on (for students), available here: https:/iot.aei.polsl.pl. You can give it a try. I’m trying to lower bandwidth by installing all needed libraries in a global cache, and I was planning to put the also our local libs using “PLATFORMIO_LIB_DIR”. When 32 students start pulling frameworks, libraries and so on parallel via the network before the first compilation, the network struggles.
Regards,
Piotr