How to use Libraries in own Library?

Hi everybody,

i just startet to work my own library for an wii motion plus board via I²C.

But for some Reasons i'm not able to use the Wire library, even if i included "../Wire/Wire.h" and WProgram.h.

i tried several options, such as using a TwoWire variable in the class, casting it and so on.

errormessages looking like this:
xxx\Arduino\libraries\WMP/WMP.cpp:12: undefined reference to `Wire'

xxx\Arduino\libraries\WMP/WMP.cpp:12: undefined reference to `TwoWire::beginTransmission(int)'

xxx\Arduino\libraries\WMP/WMP.cpp:13: undefined reference to `TwoWire::send(int)'

xxx\Arduino\libraries\WMP/WMP.cpp:14: undefined reference to `TwoWire::send(int)'

xxx\Arduino\libraries\WMP/WMP.cpp:15: undefined reference to `TwoWire::endTransmission()'

which make me wonder, because the compiler knows that my Wire-variable is linked to TwoWire O.o

any advices which could make me us predefined libraries in my own class?

thanks!

additional code source, may help you:

#include "WMP.h"
#include "WProgram.h"
#include "../Wire/Wire.h"

WMP::WMP()
{      
      Wire.begin();      
}

void WMP::initWMP()
{
      Wire.beginTransmission(0x53);  //init WMP+ out of deactivated
  Wire.send(0xFE);
  Wire.send(0x04);
  Wire.endTransmission();
}

Did you include Wire.h in the sketch? That is necessary in order for the compiler to know that it needs to compile and link with Wire.cpp.

damn, that was the problem -.-

ARG, never thought that i need to include Wire there as well, i thought including it in my library .h would be enough.

thank you very much! Quick & correct answer :slight_smile:

I recently ran across the same problem. Including Wire.h in my sketch was my solution as well.

Why do we have to include it in the sketch if it's included in another included header file?

Also, which is correct?

#include <Wire.h>

or

#include "Wire.h"

Rx

Why do we have to include it in the sketch if it's included in another included header file?

The explanation was given somewhere in this thread
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260904176

Eberhard

The Arduino IDE calls the compiler for the sketch and any .cpp files that correspond to header files that are included in the sketch. It does not read through the included files to see if they include anything.

The <> tell the compiler to look in a standard set of places for the file to include. The "" tell the compiler to look in the standard places plus the Arduino-specific places for the include file.

Which set to use depends on where the include file is located, and whether there is (potentially) a local copy that you want to specifically include or exclude. Most of the time, it makes no difference.

Yo, dawg...

Had to do it...

:smiley:

[edit]

I decided to change it because a) it was hotlinked, and they might change the image, b) it was a bit juvenile, even though it fits, and c) its been up long enough...

:slight_smile: