Library compilation fails to locate other source files

This is most likely an issue with a very simple answer. I’m trying to move an Arduino project that uses the ArduinoJoystickLibrary (github.com/MHeironimus/ArduinoJoystickLibrary). Admittedly, the GitHub repo has a less than ideal layout for use with PlatformIO, but I see no reason why it shouldn’t work. I’ve mentioned in the platformio.ini as such:

lib_deps = 
  ...
  https://github.com/MHeironimus/ArduinoJoystickLibrary

but upon compilation, I get this:

In file included from .piolibdeps\ArduinoJoystickLibrary\Joystick\src\Joystick.cpp:21:0:
.piolibdeps\ArduinoJoystickLibrary\Joystick\src\Joystick.h:24:35: fatal error: DynamicHID/DynamicHID.h: No such file or directory
compilation terminated.

The issue appears to be that PlatformIO isn’t able to see that the DynamicHID/DynamicHID.h include in Joystick.h is present as ./DynamicHID/DynamicHID.h relative to the header file.

My first thought was to add the ./DynamicHID folder to the include path, but it doesn’t seem like there’s a way to do that here… How can this be made to compiler properly?

This worked for me…

[env:micro]
platform = atmelavr
board = micro
framework = arduino
build_flags = -I.piolibdeps/ArduinoJoystickLibrary/Joystick/src
;build_flags = -I.pio/libdeps/micro/ArduinoJoystickLibrary/Joystick/src 
lib_deps = 
  https://github.com/MHeironimus/ArduinoJoystickLibrary

Explanation: build_flags -I adds a directory to the list of directories to be searched for headers. I gambled on PIO working relative to the project folder, so could just tell it to use the path relative to that. Because it’s looking for DynamicHID/DynamicHID.h, I added the path to the folder containing DynamicHID, hence src. PlatformIO v4 has a slightly different structure… and also includes the environment name (creatively named micro in my case)…

1 Like

Ah, that works perfectly. As always, @pfeerick is my savior! :smile: I’m not sure how I missed that in the docs…

1 Like

Now now… don’t make my head :balloon: :stuck_out_tongue:

Well, in your defence… there are a lot of options :laughing: … it’s easy to get lost in them… :wink:

1 Like