Including Arduino libraries together with private libraries [solved]

Hello,

.NET developer here. I’m very new to PlatformIO so please bear with me

I’m probably missing something but I am struggling with the libraries. For new projects I get a “lib” directory that I can use for private libraries. I’ve done this with the following example class:

#~\lib\StringHelpers\StringHelpers.h

#include <WString.h>

class StringHelpers
{
  public:
    static unsigned int GetInt(const String input, const String from);
};

unsigned int StringHelpers::GetInt(const String input, const String from) {
  int index = input.indexOf(from);
  if (index > 0)
    return input.substring(index + from.length()).toInt();

  return 0;
}

That seems to work fine. However, I cannot reference any Arduino libraries located in the libraries folder without adding this line to the platformio.ini:

[platformio]
lib_dir=~\Documents\Arduino\libraries

When I add this line I can include Arduino libraries but that private library can’t be found:

src\main.cpp:2:27: fatal error: StringHelpers.h: No such file or directory
#include <StringHelpers.h>

Is this expected?
How should I go about this, can I have multiple library directories?
Should I only create libraries in the Arduino libraries directory?

Let’s say I decide to create a library in the Arduino libraries directory and have it not be a part of my sketch-project. Can I still peek into the files using “Go to declaration”?

Very curious about your thoughts, thanks.

  1. I don’t recommend to use libraries installed by Arduino IDE. Please use our Library Manager
  2. Nevertheless, if you need them, please remove lib_dir=~\Documents\Arduino\libraries line from [platformio] and use lib_extra_dirs instead. For example.
[env:myenv]
lib_extra_dirs = ~\Documents\Arduino\libraries

Allright. I’ve tried this and I still get a compilation error:

src\main.cpp:3:24: fatal error: StackArray.h: No such file or directory
#include <StackArray.h>

^
compilation terminated.

The platformio.ini looks like this:

[platformio]
; lib_dir = ~\Documents\Arduino\libraries

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
lib_extra_dirs = ~\Documents\Arduino\libraries

I’ve found a way to get this to work.

My current project now includes Arduino libraries and also includes a private library in the “lib” folder.

This is what the platformio.ini looks like:

[platformio]
lib_dir = ~\Documents\Arduino\libraries

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
lib_extra_dirs = .\lib

Thanks for the help!

I’ve read your comment about not using the Arduino libraries and I am curious as to why that is? What makes the package manager and libraries in platformio better than Arduino’s libraries? The reason I ask is because I much prefer the Arduino ecosystem for now and I am new to platformio.

PlatformIO proposes developer professional project management workflow. You can depend on specific libraries or their versions. It allows having projects with isolated dependencies. Arduino IDE keeps all libraries in the one location and all project use them. It can create a ton of issues when you update some library and some code from the other project doesn’t work with it.

See example how companies use PlatformIO Library Manager

1 Like