You don’t have to use the build_flags for this.
Here is a workflow / file structure that solves your problems.
- Convert the header files into libraries (by adding some sub folder’s and the library.json)
- Create a folder structure for your projects and local libraries like so:
.
├── libraries
│ ├── LibA
│ │ ├── src
│ │ │ ├── LibA.cpp
│ │ │ └── LibA.h
│ │ └── library.json
│ ├── LibB
│ │ ├── src
│ │ │ └── LibB.h
│ │ └── library.json
│ └── LibC
| └── ...
└── projects
├── projectA
│ ├── .pio
│ ├── .vscode
│ ├── src
│ │ └── main.cpp
│ └── platformio.ini
├── projectB
| └── ...
└── projectC
└── ...
Use symlink in the lib_deps section in the platformio.ini for the corresponding projects:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
symlink://../../libraries/LibA
symlink://../../libraries/LibB
You can also use absolute paths names for your libraries.
Then simply include the libraries to your project:
#include "LibA.h"
#include "LibB.h"
Another way is to host your libraries on github:
lib_deps =
https://github.com/sivar2311/LibA
https://github.com/sivar2311/LibB
This even allows you to use different versions of your libraries in different projects.
projectA:
lib_deps =
https://github.com/sivar2311/LibA @ 1.0.0
projectB
lib_deps =
https://github.com/sivar2311/LibA @ 1.3.2
https://github.com/sivar2311/LibB @ 2.0.0
This is more the style of the ArduinoIDE where all global installed libraries are included automatically in every project.
In PlatformIO you include libraries per project and only those who are needed by the project.
Documentation:
Creating Library
Using local libraries with symlink