Sharing source files between 2 pio projects

Hi, I am working on a system with 2 components that contain similar firmware modules.

Of course, the development will become chaotic if I copy the common class files in both platformio projects.

Is there a way I can include an external file in my platformio projects, so that I do not have to maintain 2 copies of the same files at the same time?

Thanks a lot!

Sounds to me as if you may want to put the classes in a library folder and then use lib_extra_dirs in both projects to refer to that one and the same library folder.

1 Like

Best idea ever!
I cant seem to compile a library for now however. I made a folder called libraries with my library in it, called test, heres the structure:


in my .ini file, I set it up this way with an absolute path

lib_extra_dirs = C:\Users\jcbsk\Documents\Libraries

and I get this error
*** [.pio\build\esp32thing\firmware.elf] Implicit dependencyC:\Users\jcbsk.platformio\platformsz``\espressif32\builder\lib_extra_dirs' not found, needed by target .pio\build\esp32thing\firmware.elf’.`

1 Like

The structure looks okay. What’s the full platformio.ini?


That was my mistake, there was a space before lib_extra_dirs !! Now it works

I have another problem howver, most of my libraries need to be aware of Arduino.h.

How can I include Arduino.h in a library, I only have a src and an include folder with the relevant library files, so of course it doesn’t know where to search for the Arduino.h file!

1 Like

If your project is configured for arduino = framework then the library code can #include <Arduino.h> without any additional configuration. The arduino core is automatically in the global include path.

You will probably see red squiggles with Arduino.h not found if you open the file on its own workspace in VSCode – this is because that workspace probably does not have .vscode/ folder with the c_cpp_properties.json to tell it all the include files. This is an intellisense problem, it will build regardless. If you have the above setup, you can just copy-paste the .vscode folder from the project folder you’re using the library in to the library folder.