I'm currently writing an Arduino library and I want to include files in a subdirectory within the library folder. More specifically, I want the files to be accesible from the Arduino sketch.
This is my directory structure:
MyLib/MyLib.cpp
MyLib/MyLib.h
MyLib/Extra/SomeNiceFunctions.cpp
MyLib/Extra/SomeNiceFunctions.h
This is how I'm trying to include the file:
#include <MyLib.h>
#include <Extra/SomeNiceFunctions.h>
Obviously this is wrong because of the way the IDE is including the library folders. What else should I try? I could split the Extra folder to another "Library" (another folder) but that's not what I'm after.
EDIT: This is the error I'm getting undefined reference to 'font8x8'
. This is defined in Extra/SomeNiceFunctions.h
.
"Open your Arduino IDE, and from the menu, choose Sketch / Include library / Add file. A file requester will open. Navigate to your file, and click the “Open” button. The library will be installed and ready to use."
They were introduced in Arduino 0004. To use an existing library in a sketch simply go to the Sketch menu, choose "Import Library", and pick from the libraries available. This will insert an #include statement at the top of the sketch for each header (. h) file in the library's folder.
#include is used to include outside libraries in your sketch. This gives the programmer access to a large group of standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino.
In the Arduino IDE, navigate to Sketch > Include Library > Add . ZIP Library. At the top of the drop down list, select the option to "Add .
Don't use
#include <MyLib.h>
#include <Extra/SomeNiceFunctions.h>
instead use
#include <arduinolib.h>
#include "MyLib.h"
#include "Extra/SomeNiceFunctions.h"
Using angle-brackets, the compiler looks in the standard-folders for include-files. You want your custom files in your working directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With