HID.h Not found when using Arduino-libs/keyboard.h

I am using Ubuntu and tried working on a simple program on the Arduino micro pro ( I tried 2 board configs, micro and micro pro 5v) with keyboard.h. It will not compile as it does not find HID.h!
I tried re-installing keyboard.h library, re-installing atmel-avr platform.
I am able to upload a simple main with hello world (no keyboard.h) however, so no hardware issue.
Any idea what could be wrong? I didnt try on my windows laptop

I can’t reproduce that with

platform = atmelavr
board = sparkfun_promicro16
framework = arduino
lib_deps = arduino-libraries/Keyboard@^1.0.4

and src/main.cpp of

#include "Keyboard.h"

void setup() {

void loop() {

Try the same config and source file and if that still fails,

rm -rf ~/.platformio/.cache
rm -rf ~/.platformio/lib
rm -rf ~/.platformio/packages/framework-arduino-avr

and retry.

I tried this morning with my Windows and I do not have the problem. I will investigate and get back to you!

I encountered the same issue.
although I have HID.h in the Arduino core, the include can’t find it.
my solution was to change Keyboard.h so that I directed it straight to the correct header.
#include “HID.h”
#include “…/…/libraries/HID/src/HID.h”
it now compiles (I haven’t checked that it works yet)
I assume the correct fix would be something else, but since I don’t know how PIO redirects include statements, this is just an awkward workaround.

With which platformio.ini is that? That should not occurr at all.

this is my platformio.ini:

platform = atmelavr
board = sparkfun_promicro16
framework = arduino
lib_deps = 
	adafruit/Adafruit SSD1306@^2.5.7

I don’t see any problem.

Can you use this exact minimal code

#include <Arduino.h>
#include <Keyboard.h>
#include <Adafruit_SSD1306.h>
void setup() { 
void loop() {}

and then remove the .pio folder of the project. Build again. Does the build fail?

@maxgerhardt - this minimal code does compile.
so I went ahead and commented out #include <Keyboard.h> (since in my project I didn’t add it yet). and then the problem occurs.
it’s true, I would’ve added the include eventually so it’s my mistake, but if you’d like to try and debug/see for yourself, I think that’s how to get to it.
thanks for the help!!
I hope this thread will help others as well.

Well that’s the error then. It’s a fundumantal property in PlatformIO that when you only add a library via lib_deps but do not reference in the code, the Library Dependency Finder does not resolve the dependencies of that library – this since Keyboard.h needs HID.h, but HID.h is not added to the include path when building Keyboard.h, it fails immediately. For correct resulst, you always need to #include a library you put in lib_deps.