Add local library to my various project

Hi everybody,

I’m new to Platformio and I’m having some trouble with libraries.

I’m building 3 projects that are almost the same except for the main files, so the easiest way to reuse the code would be to add the .h and .cpp files of all my classes by specifying the folder path of those files. I didn’t find a way to do this and I don’t know if it’s possible.

So I tried to create a library by adding the “library.json” file in the same folder where I have the “include” and “src” folders. Something like this:

.../MyLibrary
   include
      file1.h
      file2.h
   src
      file1.cpp
      file2.cpp
   library.json

But now I’m not able to add my library to my projects. I tried this in the platformio.ini:

[env:arduino_nano_esp32]
platform = espressif32
board = arduino_nano_esp32
framework = arduino
monitor_speed = 115200
upload_port = COM8
lib_deps =
	4-20ma/ModbusMaster@^2.0.1
lib_ldf_mode = deep
lib_extra_dirs =
    c:/Users/folder/to/MyLibrary

But the compiler isn’t able to resolve the “#include <…>” present in the library even if the library compiles itself.

So I tried this:

[env:arduino_nano_esp32]
platform = espressif32
board = arduino_nano_esp32
framework = arduino
monitor_speed = 115200
upload_port = COM8
lib_deps =
   4-20ma/ModbusMaster@^2.0.1
   c:/Users/folder/to/MyLibrary

But this forces me to clean and rebuild the project every time I modify something, and that would take up to 5 minutes to perform. It’s impossible to debug the code.

I’ve tried lots of combinations and I’m sure I’m missing something.

Any help appreciated.

Sounds like

1 Like

You’re right, it really sounds like that!
I am now starting to test the solution but it seems to be working well.

For anyone in the same situation, the fix was just to add “symlink://” before the path:

[env:arduino_nano_esp32]
platform = espressif32
board = arduino_nano_esp32
framework = arduino
monitor_speed = 115200
upload_port = COM8
lib_deps =
	4-20ma/ModbusMaster@^2.0.1
    symlink://c:/Users/folder/to/MyLibrary

Thanks a lot for your help!

1 Like