Error in running Tone tutorial

i tried running the tutorial posted here(http://arduino.cc/en/Tutorial/tone)
but i have been getting the following errors after compilation-->

core.a(main.cpp.o): In function main': undefined reference to setup'

undefined reference to `loop'

can i get help ?

How are you compiling it?

uhh, im using the arduino IDE :roll_eyes:

Just checking. Can you post the code you are trying to compile. The code listed on the tutorial page compiles fine.

this is the code:

#define NOTE_G3  196
#define NOTE_B3  247
#define NOTE_A3  220
#define NOTE_C4  262
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

void setup() {
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(8);
  }
}

void loop() {
}

---------------------xxxxxx---------------------
ERROR:

core.a(main.cpp.o): In function main': F:\Arduino and Processing\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to setup'
F:\Arduino and Processing\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'

Please tell me what am i doing wrong.
Thanks.

I don't know. I just compiled your code (which should be wrapped in ... tags) without any trouble. I would guess there is something wrong with your installation. Can you compile any of the example sketches?

Yes i have been able to successfully run many sketches, dont know whats going wrong with this one

I think I'd try wiping and reinstalling the IDE.

there's something up with this code or something. i'm having the same problem with the Tone tutorial. i've been working with the arduino for a couple of months, and this is the first time i've seen this error. i wiped the IDE from my computer and redownloaded the same version, and i got the same error.
for what it's worth, i'm on a PC using windows 7.
if anybody can look into this and figure it out, that would be super great. i was really looking forward to using this tutorial to play different tunes.

Are you using Agusta's code or the code from the tutorial?

I have successfully compiled both the original Tutorial code, and Agusta's.

i'm using the code from the tutorial. i've seen this issue - with the Tone tutorial - posted on other forums, and people trying to help have also been unable to replicate the problem. it's weird.
are you on a mac or PC?

I'm on a Mac. My Windows box is in use at the moment. I'll try it on there later.

bethlena:
i'm using the code from the tutorial.

Are you using the "Get Code" link?

yes, i had clicked on "Get Code" and copied and pasted the entire code.

Just tried it on my Vista 64bit machine, and Agusta's code, and the tutorial, compiled ok.

well, shoot! i wonder if it's a windows 7 issue....
has anybody else been able to get this to compile using windows 7?

No problem with Windows 7 (64 bit). This is what I did...

• Start Arduino IDE
• Navigate to the tone tutorial using my favourite web browser
• Click the first [Get Code] link...

• Press Ctrl + A to select the text
• Press Ctrl + C to copy the text
• Switch to the Arduino IDE
• Press Ctrl + V to paste
• Click the down-pointing arrow on the right side to display the Tab Menu
• Click New Tab
• Enter pitches.h and click OK
• Switch to the web browser
• Go back to the tutorial
• Click the second [Get Code] link...

• Press Ctrl + A to select the text
• Press Ctrl + C to copy the text
• Switch to the Arduino IDE
• Press Ctrl + V to paste
• Press Ctrl + R to verify

so i did it exactly the way you typed it out (using keyboard shortcuts and all) and found myself verifying the pitches.h file - which compiled. so then i changed tabs to verify the tone code.... and it compiled! and then i uploaded it, which went fine.
so does the moral of the story here state that i was supposed to compile pitches.h? would that have anything to do with it?
thanks a bunch for your help!

bethlena:
so does the moral of the story here state that i was supposed to compile pitches.h?

I'm guessing you're rather new to the world of compiled programming languages1. When you Verify or Upload, various bits are combined together ultimately becoming an "upload image"2. In compiled language parlance this is called a "build". While both the sketch tab and the pitches.h tab are included in the build, only the sketch tab is fed directly to the compiler. pitches.h is included indirectly / by reference.

In other words, it makes no difference which tab has the focus. Only the sketch (the "main" tab) gets fed to the compiler. You do not need to compile the other tabs (like pitches.h) before compiling the sketch tab.

would that have anything to do with it?

No. At this point my suspicion is that the error message you encountered was a bit different than the original error message. Precision with error messages is very (annoyingly!) important.

thanks a bunch for your help!

You are welcome! Enjoy!


1 This is not meant as an insult but merely an observation and precursor.
2 Other names are also used. HEX-file is a fairly common synonym.