PlatformIO Community

Library with dependencies from project


I have the following problem with library dependency management: One if my libraries has the following:

  1. It calls project-specific functions (i.e., implementation depends on actual hardware at hand)
  2. It uses project-specific defines (e.g., number of outputs present on hardware at hand)

I can solve 1) by declaring the respective functions extern <...> __attribute__((weak)), however 2) I could not solve.
I tried making the header file where the project-specific defines reside visible to the library by adding the respective path as an additional include-path to the build/flags-section of the library.json file.
However, either ${PROJECT_DIR} wasn’t resolved at all or preceeded with the build-directory of the library when building it.

I tried many different ways, this was one of it, they all failed.

  "name": "abc",
  "version": "0.0.1",
  "description": "",
  "build": {
    "flags": [

Does anyone know a solution to this? Am I trying to do sth stupid/unreasonable? Many thanks in advance.

So I guess my issue is either really niche or hard to solve?

If in dobut, add an extraScript reference to the library.json that resolves ${PROJECT_DIR} and adds it to the include path.

from os.path import join


(this is only added when the library’s source files are compiled, not any other libraries)

You can check that it worked by observing the output of the verbose build task for the library files.

Simplest way is to instruct library users to have build_flags = -I. in the platformio.ini.

1 Like

Cool, thanks, I’ll give that a try.

Not quite sure I follow along: That goes into the platformio.ini file of every project I’d like to use the library in question with?
What does build_flags = -I. exactly do to the include path? What does the . refer to?

. = current directory, which is the project directory.

That is the root btw, not src/ or include/.

1 Like

okay - and

propagates to the build commands for dependent libraries? I wasn’t aware that this is possible, thought each library has its own thing going.