Tedious, having to add the same library to every program

I’m making programs to use a sensor. I want a new program for each device.

So far, I’ve added the Adafruit BME280 library at least six times.

Why doesn’t adding a library add a library??

Are you installing the library on a per-project basis? Try this platformio lib -g install library_name_here the -g option makes the library global.

More info at pio lib install — PlatformIO latest documentation.

HTH

Cheers,
Norm.

Thanks Norm,
I’ve been told to avoid global libraries. My work will involve several areas that won’t overlap, so I don’t want to put them all in together. When you use the library function in PIO, it creates a library folder in the global PIO/ lib folder.

If you only ever intend to work with the one platform - say atmelavr - using the global library is ok. However, if you will be using multiple platforms - e.g. atmelavr, espressi32 and ststm32 - under no circumstances install libraries globally unless if you are 100% CERTAIN what you are doing. As installing libraries globally will result in the libraries always being parsed when you build projects, and if you have incompatible (to the project at hand) libraries installed globally, you WILL get weird errors - which I have experiences personally! :open_mouth:

1 Like

What do you mean by ‘add a library’ - is this to a different project (e.g. lib_deps? If so, each project is blank canvas - so you have to state all the dependencies and configuration parameters.

If you are having to do it multiple times within a single project (e.g. #include <SomeLib.h>) then it is to do with the order you are doing stuff, and not including stuff in the right order.

Aha! That makes sense. I’m playing with AVR and STM32 at the moment, but I have not needed any global libraries, yet!

Thanks for the explanation.

Cheers,
Norm.

1 Like

Thanks! You’re adding to my understanding.

I am using Arduinos, but I’m also working with ESP32. So I should maybe have a libraries folder for each platform.

And then I have to put them in the projects/lib folder.

If I put the library folder in the projects/lib folder, do I have to specify the lib_deps in the .ini file, or is it automatically read from the projects/lib folder when #included?

1 Like

I wrote a a couple of c++ classes for use in my AVR code, as opposed to Arduino code. They are not libraries, as such. However, I dropped the *.h files and the *.cpp files for the classes I wanted to use in a project, into the lib directory within the project’s directory.

I didn’t add any lib_deps to platformio.ini just a #include "class.h" in the main.cpp file and it worked fine. main.cpp also included another header file of its own,from the include subdirectory, and that too was found ok.

HTH

Cheers,
Norm.

1 Like