PlatformIO Community

Adding libraries to project

I’m finally attempting to make the transition from the Arduino IDE to PlatformIO IDE and, aside from a few peculiarities that I’ve yet to sort out, I’m liking it quite a lot. One thing that I can foresee being a big pain in the future, however, is the way libraries are added to a project. In the Arduino IDE, you simply download the library into the libraries folder and add #include <library.h> to the top of the script. PlatformIO, on the other hand, seems to be purely on an individual project basis, requiring you to install the library for each project that uses it, which is fine, if a bit annoying. To install the library, I go to PlatformIO>QUICK ACCESS>PIO Home>Libraries, search for the library, hit Add to Project, scroll until I find my current project, and hit add. There are two situations where I can see this process being an issue.
One, if I have Project A which uses a lot of libraries and I want to make a new project, B, that uses the same libraries, I have to go search for and install those libraries all over again. Not that terrible, but it seems really inefficient, coming from the Arduino IDE version where you just copy-paste the #include section of project A into project B and you’re good to go.
Two, and more of a concern for me, is that you have to scroll through all your projects and find the one you want to add the library to. That’s fine if you only have a couple dozen total projects, but my Arduino projects have gotten into the hundreds over the years, and I know my PlatformIO projects will get there pretty quickly. Scrolling through 200 projects to find the one I’m working on is going to be a massive pain, especially if I have combine that with concern one I mentioned earlier. Is it possible to just add the library to the current project, instead of scrolling through until you find the current project?

So my question is, am I doing this right or missing something and shooting myself in the foot doing it this way? If this is the normal way to do things, how do you manage having to install the same dozen libraries multiple times? And how do you manage having to scroll through dozens or hundreds of projects to find the one that’s open?
I’m sure these have been addressed before, but I couldn’t find anything particularly concrete in my searching.
PS. please be nice, I’m fairly new to VScode and brand new to PlatformIO. I’ve been working with the Arduino IDE for the better part of a decade so switching IDEs is taking some getting used to.


This is wanted, PlatformIO projects are supposed to be running stand-alone / contain all the needed info to compile and run the project reproducibly. If we’re just including a headername and have some global library install folder where the user dumps his libraries into, there is a) no info in the project itself what exact library was meant b) possible mismatches in versions between the original author and what library version that a new user of the project has and c) clashes between libraries would be possible since there may be e.g. a dozen libraries which implement Servo.h, but your project relies on the correct one for its architecture etc being used. PlatformIO solves this by making library selection explicit. This is good, not bad.

Note that there’s still the options for installing for

  1. a library into the global storage (C:\Users\<user>\.platformio\lib). Which is heavily discouraged due to the potential problems above.
  2. Referencing your existing Arduino IDE library folder via lib_extra_dirs. But then there’s again no concrete info on the exact used libraries and you’re just pushing the problem onto the Arduino IDE installation.

No, you just open the first project’s platformio.ini which contains the lib_deps expression of your installed libraries and copy that over to your new project’s platformio.ini.

Does your VSCode workspace have 200 project folders loaded into it on the left file explorer side?

Yeah I understand the benefits of managing the libraries by individual project, and that how I’m planning to structure my projects, it’s just more tedious to do it that way, in my opinion. However, that global storage thing sounds like the solution for when I don’t want to individually select libraries.

Ah, I thought that installing the library literally downloaded the library source code into the project folder, I didn’t realize you could just copy-paste the dependencies section of the .ini file. That helps a lot.

No, I only have one project open at a time, maybe two if I forgot to close one before opening the next. I’m still having to scroll through all my existing projects, not just the one or two open ones, each time I install a library. Am I missing something with this?

Well in that case I think an improvement to the library manager GUI is to only consider projects within the VSCode workspace, not all ever-created projects PlatformIO keeps track of. Can you file an issue in with a screenshot of what it looks like for you?

1 Like

I’ll move over there and ask around.
Thanks for your help here!

Hijacking the conversation a bit, sorry for that.

I’m using the same method as @joshuaeblackburn of adding libraries to my project and the libraries themselves are installed in the folder .pio/libdeps/esp32-poe-iso. Now I get the error “Multiple requests to rebuild the project IntelliSense index” which is mentioning that one should never install libraries in that folder. Am I doing something wrong or is PlatformIO not following it’s own rules?

@joshuaeblackburn I think you can transfer dependencies from project to project by copying & pasting the lib_deps property from/to the corresponding platformio.ini file.