How to correctly specify libraries in platformio.ini?


#1

Hi all,
Using Platformio via VSCode. I’ve read that the best way to specify libraries would be to add them to platformio.ini. So I tried something like this (which works)

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
ESP32 BLE Arduino

However, if I try to add more libraries to clean up my code a little, removing this in my main.cpp

// in main.cpp
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

and modify my platformio.ini like this …

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
# Using a library name
Arduino
ESP32 BLE Arduino
BLEDevice
BLEServer
BLEUtils
BLE2902

Then I cannot get my sketh to compile and intellisense complains about not finding anything (which gives also some not so nice red squigglies everywhere)

What am I doing wrong?


#2

Please read https://docs.platformio.org/en/latest/librarymanager/quickstart.html

lib_deps is intended to download external libraries.


#3

Thanks for the super fast feedback.
So would it be correct to remove Arduino from platformio.ini but still keep the other ones?


#4

This is a valid config

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
  ESP32 BLE Arduino

and in CPP

// in main.cpp
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

#5

Hi,

Ok, thanks for the clarification. So best practice would be to use that only for libraries that need to be procured over the net and keep all the rest in the sketch file, correct?