Pages: [1]   Go Down
Author Topic: 'Wire' was not declared in this scope  (Read 3810 times)
0 Members and 1 Guest are viewing this topic.
Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Thanks!
Logged

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://rubenlaguna.com/wp/2009/03/19/arduino-library-for-hmc6352/

http://todbot.com/blog/2008/02/18/
Logged

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Spokane, Washington
Offline Offline
God Member
*****
Karma: 0
Posts: 686
My name is Bob, and I'm an addict.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).  
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this help...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260640627/5#5
Logged

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: December 29, 2009, 11:16:29 pm by clappro33 » Logged

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Quote
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:
#include <Wire.h>
« Last Edit: December 30, 2009, 12:36:17 am by bcook » Logged

Los Angeles, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Whoops! Thanks for catching that.

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

Pages: [1]   Go Up
Jump to: