How to make platformio knows that where the libraries locate at?

Hi, there are some libraries locate at the arduino-ide installation path, such as:
2
What I used to was copy these libraries to the path:
C:\Users\wgt.platformio\lib
So I can use these libraries in platformio-ide conveniently.
But if I don’t copy them to the path ….platformio\lib , is there anyway to make platformio knows the location of there libraries? Just like I copy them to the path ….platformio\lib .
Best regards.

You can specify an additional libraries directory in platformio.ini using lib_extra_dirs.

Having said that: I strongly suggest using lib_deps instead. You just declare the library in platformio.ini. No need to download anything. PlatformIO will take care of it, e.g:

lib_deps =
    Mouse
    IRRemote

That’s the state-of-the-art way of developing software.

3 Likes

Thanks a lot @manuelbl
It’s amazing. Now I understand the usage of lib_deps.
In the platformio.ini file:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = 
    SD
    IRremote

I find that the libraires introduced by lib_deps automatically located at the following path after compiling:
Snipaste_2020-08-22_14-47-56
What’s the mechanism behind this approach? In the platformio.ini file, I just set

 lib_deps = 
    SD
    IRremote

I didn’t specify a URL or a path, how does the platformio know that where to download the libraries of SD and IRremote?
Best regards.

PlatformIO maintains a library registry. That way it knows how to located many popular libraries. The registry can be searched from the Libraries section of PlatformIO Home or from the Libraries.

If a library is not available in the registry but has a GitHub repository (including a library.properties file), you can specify the GitHub URL in lib_deps. e.g:

lib_deps =
    https://github.com/gioblu/PJON.git
3 Likes

Thank you very much @manuelbl
The design concept of platformio is very advanced.

Hi, @manuelbl
I find that sometimes two libraries using the same name, for example:


In the paltformio.ini file, the lib_deps:

lib_deps = 
    SD

And in the library.json file of SD library, I find that the SD library introduced by lib_deps=SD download from adafruit.
3

But there are two libraries, both of them named “SD”, as the first picture illustrated, one is created by adafruit, another is created by arduino. If I want to use the SD library created by arduino, I can set lib_deps to the GitHub URL of SD library created by arduino. Is it the only method? namely, the library name, “SD”, setted to lib_deps, can not distanguish “SD” by arduino from “SD” by adafruit ?
Best regards.

The name of a library can indeed be ambiguous.

In such cases, you can specify the library by its ID. To do so, click on the search result and select the tab Installation. It will then show different options for specifying the library in platformio.ini, including the ID.

And example for the information on the Installation tab is:

[env:my_build_env]
platform = infineonxmc
framework = arduino

lib_deps =
  # Using a library name
  SD
    
  # ... or using library Id
  868
      
  # ... or depend on a specific version
  SD@1.2.4
    
  # Semantic Versioning Rules
  # http://docs.platformio.org/page/userguide/lib/cmd_install.html#description
  SD@^1.2.4
  SD@~1.2.4
  SD@>=1.2.4

So for Adafruit’s SD library, you would specify:

lib_deps =
    161

For Arduino’s SD library:

lib_deps =
    868

The upcoming PlatformIO Core 4.4 will bring support for scoped packages. This should solve an issue with duplicated package names. The format will be next:

lib_deps = 
   owner/pkgname @ requirements

@ivankravets I’ve also noticed that searching for “SD” in the library registry (PlatformIO Home and web site) returns no results even though there are two libraries named SD. It might be an opportunity to fix this as well.

1 Like

Thank you @manuelbl
Now I can distinguish with them.

Thanks @ivankravets
The paltformio is a great project.

1 Like

Thanks, fixed! We indexed words with >=3 of length for search. Changed it to >=2.