Go Down

Topic: undefined reference to 'loop' building TESTexample library (Read 1 time) previous topic - next topic

mafox296

I have a new UNO R3 board and am on a windows 7 machine. I have attempted to load the example library TEST, which produces the error undefined reference to 'loop'. Even though I believe the problem is in the linkage of the libraries, I really need explicit steps in how to correct this or another work around.

Grumpy_Mike

#1
Feb 07, 2012, 06:39 pm Last Edit: Feb 07, 2012, 07:00 pm by AWOL Reason: 1
Quote
I have attempted to load the example library TEST, which produces the error undefined reference to 'loop'.

So post the code and the error message.

Moderator edit: topic moved, thanks Mike.

mafox296

The only reference to "loop" is in doing_something.pde
provided with the TEST library
i.e.
void loop()
{
  myTest.doSomething();
  delay(500);
}

The error produced is  .../arduino\cores\ardino/main.cpp:14:
undefined reference to loop
Interestingly if the all to loop is commented out in doing_something.pde the same error is produced.
I'm totally confused .


pYro_65

Post the actual sketch file or code. That error is commonly linked to incorrect function names, can your sketch see the setup function and is it in the same file as the loop function.
Ensure the 'loop' word is all lowercase.
Also if you are using the latest arduino ( 1.0 ) you should rename your .pde file to .ino

mafox296

Things are really bizarre.
First as requested here's the sketch as it appears from the Arduino web site.
include <Test.h>

// Doing Something
// by John Doe <http://www.yourwebsite.com>

// Demostrates how to do something with the Test library

// Created 1 April 2006

Test myTest = Test(2);

void setup()
{
}

void loop()
{
  myTest.doSomething();
  delay(500);
}
second I tried other provided  libraries and got the same error
third   I made a bare library with only an .h file and a .cpp file.
the only entry is the include directive. No matter what I do by way of adding code I get the same same error.
I must conclude that I think there is something wrong with the core library, at least when it comes to importing libraries.
I do not know how to re-implement the embedded software and would  value some help.

PaulS

Quote
I have attempted to load the example library TEST, which produces the error undefined reference to 'loop'. Even though I believe the problem is in the linkage of the libraries, I really need explicit steps in how to correct this or another work around.

Where did you get this library? The include statement is wrong in the code you posted. The # is missing.

If you are really interested in help. you'll copy and paste code properly, and provide a link so other people can look at the actual library.

mafox296

I got the library from the site http://www.arduino.cc/en/Main/Libraries by clicking on the Test library link and adding the unzipped down load into a sub folder of the library folder.
I also tried using the Time library from the Arduino library web site. I further tried a library from the provided libraries.
All these experiments gave the same undefined loop error in min.cpp  line 14 which is loop();
the code block there is
for (;;) {
      loop();
      if (serialEventRun) serialEventRun();
   }

Nick Gammon


the code block there is
for (;;) {
      loop();
      if (serialEventRun) serialEventRun();
   }


Time to learn about code blocks. Edit your post, select the code and hit the "#" button.

Nick Gammon

Quote
All these experiments gave the same undefined loop error in min.cpp 


min.cpp?

Copy and paste the actual message.

Nick Gammon


I have attempted to load the example library TEST


What example library TEST? Where did you find that?


mafox296

The reference to line 14 is in main.cpp.
The code for this is in ../hardware/arduino/cores/arduino
it is short therefore I reproduce it here.:
#include <Arduino.h>

int main(void)
{
   init();

#if defined(USBCON)
   USB.attach();
#endif
   
   setup();
   
   for (;;) {
      loop();
      if (serialEventRun) serialEventRun();
   }
       
   return 0;
}
I note that it contains the include directive
#include <Arduino.h>
which contains the definition of loop i.e
void loop(void);
So I must assume that somehow the complied and cached library is different from the code as if I make a simple sketch , that contain a loop, not relying on any of the imported libraries, it compiles and runs correctly. When any library is imported the error is displayed. It is not the library but something to do with how the library is linked. At this point I am lost.

mmcp42

put your code inside code tags

[ code]
your code
[ /code]
then we see code not smilies!
there are only 10 types of people
them that understands binary
and them that doesn't

mmcp42

hrumph
why don't you use the code in the example
Code: [Select]

#include <Test.h>

// Doing Something
// by John Doe <http://www.yourwebsite.com>

// Demostrates how to do something with the Test library

// Created 1 April 2006

Test myTest = Test(2);

void setup()
{
}

void loop()
{
 myTest.doSomething();
 delay(500);
}


I changed the includes to run under IDE 1.0 and it works
there are only 10 types of people
them that understands binary
and them that doesn't

mafox296

Problem solved.
I had been using an example which had only the include directive but no code.  As soon as I put in the actual example code it worked. To further prove the point I used the more complex Time library. For this I just put in a simplified example which just printed out parts of the time. I really must thank you for your help, for though I feel that the error led me in a red herring path it was indeed a learning experience.

Go Up