Trying to understand how to install custom local library

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.


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:

1 Like

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:

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 (?)

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.

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

Glad to be of some help :slight_smile:

There a few options:

Add library to a project

Just unpack and copy the library to lib folder in your project. See example platformio-examples/unit-testing/calculator/lib at develop · platformio/platformio-examples · GitHub

Project dependency

See Redirecting...

lib_deps = /path/to/custom/library

Following platformio-examples/unit-testing/calculator/lib at develop · platformio/platformio-examples · GitHub
, I structured as such:
Under PlatformIO/Projects/test/src I have

Under PlatformIO/Projects/test/lib/ I have

  • 3 folders for 3 personal libraries, each one with its .h and .cpp file.
    for simplicity let’s call these forders: myLib1, myLib2, myLib3

  • 4 .h files
    for simplicity let’s call them UX1.h, UX2.h, myglobalsMain.h, mydebug.h

2 out of the four .h in lib are for main.cpp, namely UX1.h and UX2.h
while myglobalsMain.h (defines and globals) is common to both main.cpp and one of my library, say myLib3
while mydebug.h (C pre-processing) is common to all three libraries and main.cpp as well

PlateformIO informs me that I’m left with “5 problems”.
it claims that it can’t open the source file “mydebug.h”, so as the other .h files directly under lib

I found the solution: is to move the mydebug.h and myglobalsMain.h to the include folder.

Would you be so kind to add to

that shared includes must be in the include directory