How do I add a library using lib_deps?

I know this is a really noob question, but I have been bouncing around between various tutorials and trying to read the documentation. How do I add a libray to a project using lib_deps option?

The tutorials I come across on youtube, show that there is a way to download a library directly into my project, how ever when I open the library manager to download the library, I only have the option to download to global storage.

Then once the library is downloaded into the project, the INI file is tweaked to use the library when the program is complied.

Is there a straight forward instructions for adding a library to a project and setting up the dependencies?

I am using visual studio code with PlatformIO

Have you read Redirecting...?

1 Like

In a nutshell:

  • Go to the library registry - either via your web browser, or via the libraries view of PIO Home
  • Search for you library, and open its information page
  • Click the installation tab once you’ve found your library, and copy whichever version of the lib_deps entry you want to use - ID, by name, by name and version, etc. Choose only one line.
  • Open your platformio.ini file, and add that reference under lib_deps (adding it if missing), with a single library reference per line if you have multiple libraries to declare.

i.e. for this project, I have several libraries, and I chose to reference by ID and specify specific versions of the libraries to be used, and then used comments to remind me what id related to what library.

lib_deps = 
    1@2.3.5    ; OneWire
    38@1.6     ; LowPower
    54@3.8.0   ; DallasTemperature
    433@1.3.3  ; RF24
    1002@1.0.5 ; elapsedMillis
    1976@1.1   ; SerialCommands
2 Likes

Yes, I have read the documentation multiple times. I am still having trouble following it.

Okay, if I am following your example correctly, I don’t need to actually download the library first. I just need to set up the dependency in the ini file. Then when I complied my program, the library will be downloaded.

1 Like

Spot on. If you declare libraries via lib_deps, PlatformIO will automatically try to download them when you compile your program if they are missing.

I’m adding 2 libraries but the 2nd one always gives an Error

why the IDE can’t see it !? I think my problem occurs due to the fact that CayenneLPP library belongs to framework = arduino and I’m using espressif32. but I don’t know how to integrate both so they can work together.

Update: I tried this method

framework = arduino, espidf

here

but It doesn’t work (get install esp-windows-curses platformio Error)

Why do you think the problem lies with the framework choice? Both your libs are Arduino libraries.

Just Ctrl+Shift+P → Rebuild IntelliSense in VSCode. PlatformIO will only recognize the library dependency after it sees an include in your code referencing it, not before that. Works perfectly fine.

Thank you maxgerhardt for your reply, I followed your instructions but still have an error (don’t find the library).

I can’t reproduce that problem, with that exact platformio.ini you’re using. It may be possible that you have a corrupted library download. Delete the .pio/ folder of the project and retry building.

I did and i totally removed VSC( and all pio files from the registery ) and reinstall everything (didn’t install espressif tools this time) but the error remains the same !!

Remove the CMakeLists.txtfrom the project files (in the root and in the src/) folder. Make sure the only extensions you have installed are PIO, C/C++ by Microsoft, Python and Jupyter. If the project still not builds, please post the output the output of the project task “Advanced → Verbose Build” to pastebin.com/ and link to it here.

1 Like

My Apologise, when i tried to rewrite the .cpp file again I noticed that I was including
#include <CayenneLPPDecode.h> which is a different library than #include <CayenneLPP.h> and indeed pio is not going to find it. now it’s building successfully. Thank you.