Go Down

Topic: 'Wire' was not declared in this scope (Read 12440 times) previous topic - next topic


Hi all,

I have been trying to play with two different sketched for things on the I2C bus, but they don't seem to compile. One is a hcm5632 compass library and test sketch that I downloaded from {SEE NEXT POST} and the other is a WiiChuck library that I am creating by adapting nunchuck_funcs.h from {SEE NEXT POST}. I can get nunchuck_funcs.h to work, and I have found other code that doesn't use a library to get the compass to work, but when I try and use library, I get weird compiling errors.

So, specifically for hmc6352example.pde, I get the error:

/Applications/Arduino.app/Contents/Resources/Java/hardware/libraries/Hmc6352/hmc6352.cpp:65: error: 'Wire' was not declared in this scope

But line 22 of hmc6352.cpp is #include <WProgram.h>, so I'm nore sure why it's complaining about Wire.

I'm getting nearly the same problem with my own WiiChuck library.

After some Google searches, I have found that The Arduino IDE might be compiling things different then when the hmc6352 and example were originally made, so, for the record, my Arduino IDE is 0017.



That's kinda cool that you can't post links on the first post! Nice anti-span tactic. Though it was cumbersome for me...




So, after more debugging, I have concluded that I simply need to include Wire.h. The problem is now that I can't figure out how to do this.

Now my question is, how does one include a header in a library from another library?


There was a post about this previously.. it has something to do with how the Arduino IDE treats header files.

To solve the problem, you should be able to add the #include <Wire.h> inside the sketch you're trying to use. Somebody can explain how the headers work better, but I know the Arduino IDE has it's limitations.


CaptainObvious - Thanks for the response! I'm glad someone is listening.

So, including Wire.h in my sketch didn't fix the compile errors in the library files. And when I try to include Wire.h in the library cpp file, I get an error that says the file could not be found.

/Applications/Arduino.app/Contents/Resources/Java/hardware/libraries/WiiChuck/WiiChuck.cpp:8:18: error: Wire.h: No such file or directory


You need to include Wire.h both in your library (where you're using the things it defines) and in your sketch (which tells the IDE to include its folder in the search path for includes during compilation and to link in its .c / .cpp files).  

Coding Badly

Does this help...



Dec 30, 2009, 05:15 am Last Edit: Dec 30, 2009, 05:16 am by clappro33 Reason: 1
Coding Badly, that was exactly what I needed! I just need to add #include "../Wire/Wire.h"
instead of #include "Wire.h". Thank you very much!

I will post these object oriented library for the WiiChuck and hmc6352 soon in the libraries section of the forum.

Thanks again!


Ugh! So, although Wire.h is finally include in my library, I am getting a ton of new errors that look like this: undefined reference to `Wire'.

I feel like this is another file referencing error, and I could try copying all of the libraries into my library's folder, but that sounds messy. I guess a symbolic link would be a little nicer, but still messy.

I've been trying to find another third party, object oriented arduino library that uses Wire without luck. Does anybody know of one?

Coding Badly

Dec 30, 2009, 06:35 am Last Edit: Dec 30, 2009, 06:36 am by bcook Reason: 1

This is from the bottom of the referenced message...

The only way to get the dot-cpp files included is to add the header to the Sketch.

Adding this to the top of your Sketch should fix the problem...

Code: [Select]
#include <Wire.h>


Whoops! Thanks for catching that.

So it compiles and runs now. Though I have a few bugs to debug now...  :-/

Go Up