Where to #include other libraries in a library?

I created a class library to represent an I2C device (an MCP23017).

  • Since the class uses Wire functions, my question is where I put “#include <Wire.h>”? In the .h file, in the .cpp file, in the sketch using the library, or all three?

  • And if I include the Wire library in my library, do I need to re-include it in the sketch if I want to use other Wire functions in the sketch?

  • And what is the difference (if any) between

#include <xxxx>

and

#include "xxxx"

?

If you put the “#include <Wire.h>” line in YOUR library.h file, you should be good to go.

It does need to be included in both the library file and the sketch file. But by putting the line in your library.h file, this will happen automatically.

Don’t know the difference between the “” and the <>. My GUESS is that one looks in the directory your sketch is in, and the other looks in a library directory as defined by preferences.

Good luck!

Don’t know the difference between the “”

The preprocessor searches for the file in all the include paths plus the “local directory”. I assume “local directory” for the Arduino is the same directory as the PDE.

and the <>.

The preprocessor searches for the file in all the include paths.

Generally speaking, “” are used for files specific to a project and <> are used for library files.

  • Brian