Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include a file within a folder in an Arduino library

Tags:

c++

arduino

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.

like image 977
giannoug Avatar asked Feb 20 '13 14:02

giannoug


People also ask

How do I include a file in Arduino?

"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."

Where to put include files Arduino?

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.

What does #include do in Arduino?

#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.

How do I add code to Arduino library?

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 .


1 Answers

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.

like image 112
bash.d Avatar answered Nov 14 '22 23:11

bash.d