PlatformIO Community

Trying to understand how to install custom local library


#1

I have read the “platformio lib install” doc, however i’m not sure i understand how to do a very simple thing.

I created a small library for the esp8266, using the “arduino library rules”, it is stored on my computer in D:\library_test . I am using platformIO with atom.
I just want to be able to create as many projects i want in platformIO, and be able to add my library this way as i do with other libraries :

#include "library_test"

Now is that even possible ? I’m sorry if that sounds stupid, i am still learning.

Cheers.


#2

It is,
You can place a copy of the library under the lib folder in your project folder and include it from there.
Or you can define lib_extra_dirs path to point to your custom library and still include it from there in your project.

Hope this helps!! :slight_smile:


#3

Thank you very much for your answer Krishna !!!

About the: define a lib_extra_dirs path…Where am i supposed to define it. I read the docs again and they give this example:

[env:myenv]
lib_extra_dirs = /common/libraries

I mean if i’m supposed to be add this to the platformio.ini file, the problem is that, as each project has its own platformio.ini file, it means i will have to add this line every time i create a new project, and my “goal” would be to simply be able to add libraries from a “global” folder by simply including them with an #include, like you can do in the Arduino IDE, but may be it is not possible (?)


#4

Yes, that is correct. You will have to manually add that particular directive to all your projects. It is a small inconvenience but it does serve your purpose.

Though you might want to reach out to @ivankravets to ask if there is a way to install the specific custom library what you create in the global library storage of platformio. That way it is accessible to all the projects inside platformio.


#5

Will do.
Thank you again for taking the time to answer me, really appreciate it.
Cheers.


#6

Glad to be of some help :slight_smile:


#7

There a few options:

Add library to project

Just unpack and copy library to lib folder in your project.

Install to global storage

In this case, library will be visible for other projects. Please place/unpack your library into global storage, item #4 in http://docs.platformio.org/en/latest/librarymanager/ldf.html#storage

Using PlatformIO IDE > PIO Home

Please open PlatformIO IDE > PIO Home > Libraries > Install (Advanced library installation) and paste full path to a custom library and press “Install”.

Install using PlatformIO Core (CLI)

See https://docs.platformio.org/en/latest/userguide/lib/cmd_install.html

pio lib --global install /path/to/custon/library folder or archive

Project dependency

See https://docs.platformio.org/en/latest/librarymanager/quickstart.html#project-dependencies

[env:myenv]
lib_deps = /path/to/custom/library