I don’t know how to start a new topic.
When I load an Arduino IDE sketch into PlatformIO (VS), I still have the swiggly lines under the #include <library.h> . The libraries are already on my Windows 10 PC. How can I put them into the registry so I can use them in a sketch?
I’ve spend hours clicking and flicking but have got no where.
I don’t know how to start a new topic.
Have you tried the ‘New Topic’ button?
I’ve split this into a new topic.
You can use the
lib_extra_dirs parameter in your
platformio.ini if you want to include your existing sketchbook libraries folder in the list of folders that the PlatformIO library depenency finder will look in. Click the link to see the documentation for that parameter.
But, it is better to get familar with the PlatformIO way of managing libraries, as it gives you a lot more control over them. You basically need to search for the library in the platformio registry, so you can put the correct name in your
platformio.ini's lib_deps line. Do NOT use the install button in the library manager, as that installs the library into global storage - which you do not want to do unless you know what you are doing.
- click the platformio sidebar icon
- open the pio home libraries view and search for your library
- once you’ve found your library, click on the installation tab for it
- here is your lib_deps entry for that particular library
You should have only one
lib_deps entry, which can list multiple libraries, as well as lock them to specific versions if needed. Click the link to see the documentation for that parameter.
I, i’m totally new to platformio and want to ask why this is not the way to add library to platformio?
It is much more explicit and portable if you declare dependencies per-project in the
platformio.ini instead of relying on the library to be installed in the global library storage. That is an improvement over Arduino.
If you install a library into the global storage, PlatformIO will have to do a guess and attempt to include it in the compilation process based on header names in your code and platform / framework information. With
lib_deps you just directly state which library it is and also in what version you need it, no confusion possible.
In addition to what Max said above, if you install a library into global storage, PlatformIO may include it in a build for a platform / framework it is not compatible with, thereby breaking the compile. Installing it to your project / via
lib_deps ensures this does not happen.
So when I use the install button and click the 3 dots and install to a specific project, what does platformio actually do? Why doesn’t that simply add the entry to the platformio.ini ?
+1, I also would like to know what happens using that option…
So I was going through a similar difficulty with libraries and posted else where…
|(1)||The process for installing libraries incorrectly in PIO is easy enough:|
|a.||You go to Home>>Libraries and the first tab (Registry) is already selected. (That’s nice.)|
|b.||Type in enough of the name of the library into the search box and hit the magnifying icon, and select the library you want to install by clicking on it. (That’s nice.)|
|c.||This brings up a screen for the library with the latest version number and a big blue “Install” button next to it. (Danger ahead!)|
|d.||If you hit that button, PIO does exactly the wrong thing: It installs the library into a Global Library, something they recommend that you not do. (I find it interesting that the default action of the button does precisely the wrong thing.)|
|e.||Instead, hit the part of the blue button with “. . .” on it, and a subtle “Install to…” box appears below. (Hard to see, actually)|
|f.||Hit that “Install to…” option, and (Danger ahead!)|
|g.||a screen comes up with, again, the wrong setting of “Global” in the second box from the top. (Hmmm.)|
|h.||Hit the dropdown arrow way over to the right of the Global box, and, finally, it lists your existing projects. (Very subtle arrow, actually—missed it at first.)|
|i.||Select the Project you want to install the library for, and you’re finally done.|
I was hoping that my new way of adding libraries to projects was all I needed to do. Is that still wrong?
Installing to your project via the PIO Home GUI downloads the library files (see the change in the
.pio\libdeps\uno folder between the two screenshots) into your projects
libdeps folder, but doesn’t add it to the
lib_deps… which is quite an oversight… as well as the default of installing to global storage.