PlatformIO Community

Using Existing Arduino libraries in place

Is there a method in platformio of including all the arduino libraries and core libraries that are already in place from the arduino ide installation so that platformio can find them? Moving a simple program that contains a single #include <Keyboard.h> leads to so many failed dependencies that it is nearly impossible to quickly test something by moving it from the arduino’s ide to platformio/vscode.

Do you mean use existing libraries from an Arduino IDE install?

The lib_extra_dirs platformio.ini option should do the trick… just point it to your Arduino IDE libraries folder.

1 Like

Hello pfeerick,
Yes, I’m familiar with lib_extra_dirs in platformio.ini. My problem seems a bit more complicated…an example might help describe it…

A simple program with the line #include <Keyboard.h> compiles fine in Arduino’s IDE.

Move that same program to Platformio/vscode, and now I have several “can’t find Keyboard.h, etc…”. So I track down Keyboard.h’s library in the Arduino’s libraries, and include that in platformio’s lib_extra_dirs.

Now I have all type of “can’t find hid.h” missing files. So I manually track those down and do the same, adding the libraries to lib_extra_dirs again.

Then I have many "can’t find pluggableusb.h references and others…this process seems endless, and Arduino’s libraries are is several different places (Base, core, hardware, platform, etc?).

Ideally, there would be one single lib_extra_dirs that I could add at the root of my arduino installation that would solve this in platformio, but including the base of my arduino like that didn’t seem to help.

Alternately, a manner in platformio of “listing” every reference that is missing, but I suspect that that is impossible since if it can’t find a file, it cannot look into that file to see what is missing further up the hierarchy of prerequisites.
…or is there some better method of doing this messy process that what I am doing? In the future I’d like to keep all these third-party located libraries within my project to keep it portable, but I can’t seem to find a good method of tracking and finding them. Any other suggestions?

have same problem , any answer seems NOT POSSIBLE …

a) what arduino libraries to share with platform-IO ( is arduino-ide internal!)
B) how to force PlatformIO to liik for specific places , to find
the INCLUDES and libraries intended for question a

it is clear to me that lib_extra_dirs is not enough Nor does it work

PLease someone answer
of is there NOONE USING PLATFORM IO for the above reason !!!

Hi @dreuzel, could you please provide more details about what you’re trying to achieve?
I understand that you’d like to use Arduino libraries which are installed in Arduino IDE folders? Which ones? Can you post your project (or a minimal one which shows the problem)?

I do use PlatformIO IDE, but I use the libraries from the framework installed in PlatformIO IDE itself, the libraries installed inside the project by library manager, or the libraries which I copy to my project manually inside lib subfolder. So far so good.

1 Like

Hi @Sam, if I understand correctly, you have some libraries already installed in Arduino IDE and you’d like to import them to PlatformIO, so that they’re available for your projects?

oh … that is simple to answer:

  1. what libraries … simply all
  2. what project :
    pure minimum: rest assured works perfectly using ARDUINO IDE
            #include <arduino.h>  //added for platform IO
            #include  <a.h>    //added in any form of library 
            #include "b.h"      //added in the project  
           A a;
           B b
            setup() {
                            Serial.befin(115200);
                            a.begin();
                            b.begin();
      Serial.println(definedINa.h);
                            Serial.println(definedinb.h);

                       }
             loop() {}

Windows 10
Everything Fails except first time[FULL FRESH INSTALL OF vSCODE AND PLATFORMIo AND EXTENTIONS cPP] (file names get rewritten, and all is corrupt there after…

   dOES NOT FIND  any includes   !!!!!
   DOES NOT FIND ANY LIBRARIES  !!!!!
  cAN NOT FIND THE  AUTOINSTALLED  COMPILER 
                                                PACKAGE\TOOLCHAIN-XTENSA32\BIN\XTENSA-ESP32-ELF-GCC.EXE

IN SUMMARY ALL GLAMOR WORKS ALL ESSENTIALS fail !

@ivankravets what do you think? I can try to replicate the issue described by @dreuzel (but I cannot promise the exact timing though), but it basically boils down to automatic import of installed libraries in Arduino IDE (if it is detected).

1 Like
  1. That code does not compile on the Arduino IDE - there are typos (Serial.befin ->Serial.begin), both the setup and loop functions are missing the void return type, and as they are, the Serial.println calls are invalid, as strings should have quotes around them. However, assuming this is an attempt at a minimum code example, rather than just a copy and paste of a working minumum code example this then leads to

  2. You haven’t given an outline of the directory structure of your project… where have you installed the libraries? How are we to determine if you have correctly installed them?

  3. What is your platformio.ini configuration? Perhaps you referenced the libraries there, and got the path wrong… are we to just guess that?

  4. You say it can’t find the 'auto-installed compiler`… so what is the error message that you are getting when compiling/building the code? Why haven’t you given us the compile log, so we can see the actual error, and perhaps diagnose what is wrong?

  5. “(file names get rewritten, and all is corrupt there after…” I strongly doubt that, unless this project is on a network share, as file corruption when compiling stuff is not unheard of. And PlatformIO doesn’t rename files in your project, so that is being done by something else.


As an example… the following code (which just serial prints loop every 500ms, using the elapsedmillis library and objects) and platformio.ini compiles just fine for me, and should also work on the Arduino IDE with no changes. Feel free to try it, and even change the platform and board since from other posts it seems like you’re using ESP32 stuff. Now, if it doesn’t work, please give the error message/build log, and we can start trying to work out what is wrong.

main.cpp

#include <Arduino.h>
#include <elapsedMillis.h>

elapsedMillis loopTimer;

void setup()
{
  Serial.begin(9600);
  Serial.println("setup()");
}

void loop()
{
  if (loopTimer > 500)
  {
    Serial.println("loop()");
    loopTimer = 0;
  }
}

platformio.ini

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