I'm struggling a bit with Arduino language + its IDE not being 100% real C++. I wrote my own I2C library for a sensor but can't get the IDE's compiler to recognise it. I'm using Ubuntu 18.04.

I get no such file or directory for all of these things I've tried:

  • Include the .h file by absolute and relative path in the .ino code
  • Put .cpp + .h files in ~/Arduino/libraries
  • Put .cpp + .h files in ~/sketchbook/libraries
  • Put .cpp + .h files in ~/sketchbook/libraries/mylibrary
  • Put .cpp + .h files in ~/sketchbook/libraries/mylibrary and try to "install" the library in the IDE (Sketch -> Include library -> Manage libraries; it's not listed)

I'm following the official guide here. Any ideas on how to get the compiler to recognise my library?

1 Answer 1


You need to:

  1. Create the folder ~/Arduino/libraries/MyLibrary
  2. Place the library files in there named as:
    • ~/Arduino/libraries/MyLibrary/MyLibrary.h
    • ~/Arduino/libraries/MyLibrary/MyLibrary.cpp
  3. Restart the IDE if it is running
  4. Use #include <MyLibrary.h> in your sketch

This is assuming your sketchbook is set to ~/Arduino - change that to wherever the sketchbook is set to (check in Preferences for that location).

Note that in Linux capitalisation is important. The filesystem is case sensitive, and the name of your folder should have the same name and capitalisation as the name of your header file.

  • No, but what capitalisation you use on your files you should also use on the folder, and you must use in the #include.
    – Majenko
    Jul 8, 2018 at 11:00
  • I'm not sure how critical it is, but it should be the same as the .h file.
    – Majenko
    Jul 8, 2018 at 11:01
  • You're right, it was the sketchbook location. I had fiddled with my installation a few times, and hadn't updated the preferences. Thank you.
    – Escher
    Jul 8, 2018 at 11:02
  • 1
    I would add that the source files can be in src subfolder of the library folder to not mix them with library configuration files and github readme file if you want to publish the library. ~/Arduino/libraries/MyLibrary/src/MyLibrary.h github.com/arduino/Arduino/wiki/…
    – Juraj
    Jul 8, 2018 at 11:13
  • 1
    Only if you have a library.properties (or whatever it is) to describe the library...
    – Majenko
    Jul 8, 2018 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.