undefined reference to 'setup'/'loop'

I'm writing a program for a fancontroller. I'm in a very early stage of the program (only defined some variables, pins and EEPROM memory locations and written a simple get-values-out-of-EEPROM fucntion) but wanted to check for syntax errors. Weirdly, the compiler gave me two errors: "undefined reference to 'setup'" and 'undefined reference to 'loop'". Does anyone know what this means and how I can fix it?

Code=

/*
 *Fancontroller
 *Author: Simon Beirnaert
 */
 
 //EEPROM memory map
 #define FIRSTRUN 512    //Obvious
 #define TRESHOLD 0      //Joystick treshold
 #define O1STATUS 1      //(1=active)
 #define O2STATUS 2      //(1=active)
 #define O3STATUS 3      //(1=active)
 #define I1STATUS  4     //(0=inactive, 4=active, 1-3=channel assignment)
 #define I2STATUS  5     //(0=inactive, 4=active, 1-3=channel assignment)
 #define I3STATUS  6     //(0=inactive, 4=active, 1-3=channel assignment)
 #define I4STATUS  7     //(0=inactive, 4=active, 1-3=channel assignment)
 #define I5STATUS  8     //(0=inactive, 4=active, 1-3=channel assignment)
 #define I6STATUS  9     //(0=inactive, 4=active, 1-3=channel assignment)
 #define ESSTATUS  10    //Emergency shutdown (1=active)
 #define ESTEMP1   11    //Emergency shutdown temp sensor 1 (0=disabled)
 #define ESTEMP2   12    //Emergency shutdown temp sensor 2 (0=disabled)
 #define ESTEMP3   13    //Emergency shutdown temp sensor 3 (0=disabled)
 #define ESTEMP4   14    //Emergency shutdown temp sensor 4 (0=disabled)
 #define ESTEMP5   15    //Emergency shutdown temp sensor 5 (0=disabled)
 #define ESTEMP6   16    //Emergency shutdown temp sensor 6 (0=disabled)
 #define MINRPM1   17    //Minimum RPM channel 1
 #define MINRPM2   18    //Minimum RPM channel 2
 #define MINRPM3   19    //Minimum RPM channel 3
 #define MAXRPM1   20    //Maximum RPM channel 1
 #define MAXRPM2   21    //Maximum RPM channel 2
 #define MAXRPM3   22    //Maximum RPM channel 3
 #define TYPE1     23    //0=fan 1=pump
 #define TYPE2     24    //0=fan 1=pump
 #define TYPE3     25    //0=fan 1=pump
 #define GOAL1     26    //Desired temperature channel 1
 #define GOAL2     27    //Desired temperature channel 1
 #define GOAL3     28    //Desired temperature channel 1
 #define XMIN      29    //X-value on complete left
 #define XMAX      30    //x-value on complete right
 #define YMIN      31    //Y-value on complete down
 #define YMAX      32    //Y-value on complete up
 #define MODE      33    /*0=air (no cooperation between channels)
                          *1=water (channel 2(exhaust fan) and 3(pump) cooperate)
                          *3=water (user defined pump/fan channels, no cooperation)
                          *4=user defined code
                          */
                          
 //Defines
 #define OCH  3    //Number of output channels
 #define ICH  6    //Number of input channels
 
 //includes
 #include <EEPROM.h>
 
 //Pin assignment
   //Output channels
 const int och[OCH]={9,10,11};
   //RPM sensors
 const int rpmsens[OCH]={6,7,8};
   //LCD pin
 const int lcd=2;
   //Inputs
 const int xaxis=0;
 const int yaxis=1;
 const int ich[ICH]={2,3,4,5,6,7};
 
 //Global variables
 int pwm[OCH]={255,255,255},           //Output channel PWM value
     adc[ICH],                         //Input channel ADC value
     temp[ICH],                        //Input channel temp
     ostatus[OCH],                     //Output channel status
     istatus[ICH],                     //Input channel status
     rpm[OCH],                         //Output channel RPM
     esstatus=0,                             //Emergency shutdown enable
     estemp[ICH],                      //Emergency shutdown temps
     minrpm[OCH],
     maxrpm[OCH],
     type[OCH],                        //Output channel type
     goal[OCH],                        //Desired temperartures
     ymin,ymax,yval,ytresh,ycenter,    //Needed values for y-axis
     xmin,xmax,xval,xtresh,xcenter,    //Needed values for x-axis
     mode;                             //Operating mode
     
 //Functions in order of declaration below loop()
 void firstRun(void);
 void loadValues(void);

 void setup()
 {
   
   if(EEPROM.read(FIRSTRUN)) firstRun();

   loadValues();
 }
 
 void loop()
 {
     
 }
 
 void loadValues(void)
 {
   int i;
   
   for(i=0; i<OCH; i++)
   {
     ostatus[i]=EEPROM.read(O1STATUS+i);
     minrpm[i]=EEPROM.read(MINRPM1+i);
     maxrpm[i]=EEPROM.read(MAXRPM1+i);
     type[i]=EEPROM.read(TYPE1+i);
     goal[i]=EEPROM.read(GOAL1+i);
   }
   
   for(i=0; i<ICH; i++)
   {
     istatus[i]=EEPROM.read(I1STATUS+i);
     estemp[i]=EEPROM.read(ESTEMP1+i);
   }
   
   esstatus=EEPROM.read(ESSTATUS);
   xmin=EEPROM.read(XMIN);
   xmax=EEPROM.read(XMAX);
   ymin=EEPROM.read(YMIN);
   ymax=EEPROM.read(YMAX);
   mode=EEPROM.read(MODE);
   
   xcenter=(xmax-xmin)/2;  
   ycenter=(ymax-ymin)/2;
   xtresh=(xmax-xmin)*(5/100);
   ytresh=(ymax-ymin)*(5/100);
 }

 void firstRun(void){}

I don't know the fix but, if you comment this part out the errors you reported go away. Of course you get new errors.

 //Global variables
/* int pwm[OCH]={255,255,255},           //Output channel PWM value
     adc[ICH],                         //Input channel ADC value
     temp[ICH],                        //Input channel temp
     ostatus[OCH],                     //Output channel status
     istatus[ICH],                     //Input channel status
     rpm[OCH],                         //Output channel RPM
     esstatus=0,                             //Emergency shutdown enable
     estemp[ICH],                      //Emergency shutdown temps
     minrpm[OCH],
     maxrpm[OCH],
     type[OCH],                        //Output channel type
     goal[OCH],                        //Desired temperartures
     ymin,ymax,yval,ytresh,ycenter,    //Needed values for y-axis
     xmin,xmax,xval,xtresh,xcenter,    //Needed values for x-axis
     mode;
Binary sketch size: 1016 bytes (of a 30720 byte maximum)

I just removed the // comments from the end of all #define.

fuh:
I just removed the // comments from the end of all #define.

It apparantly works too when you change

 #define MODE      33    /*0=air (no cooperation between channels)
                          *1=water (channel 2(exhaust fan) and 3(pump) cooperate)
                          *3=water (user defined pump/fan channels, no cooperation)
                          *4=user defined code
                          */

into

 #define MODE      33    //0=air (no cooperation between channels)
                         /*1=water (channel 2(exhaust fan) and 3(pump) cooperate)
                          *3=water (user defined pump/fan channels, no cooperation)
                          *4=user defined code
                          */

Do you (or anyone else here) have any idea why these errors are displayed?

I think this is the bug that crops up occasionally. If you add

const int dummy = 0;

to the start of the sketch, it compiles ok.

I can't remember the details, but it's something to do with the way the IDE pre-processes the sketch.

I have met this problem before
I found that the problem is I am using "main" as the sketch's name.
May be we cannot use "main" as a sketch name.
So I change the name, and then problem solved.

I don't think my problem is the same as the above people but I am getting same error. I have never seen this error before.

I think I am having some troubles not knowing how to properly link two functions in this case void time() and void loop (). I don't even really know what the 'main function is.

this is the error
Arduino: 1.5.5 (Windows 7), Board: "Arduino Uno"

C:\Users\JACOBH~1\AppData\Local\Temp\build6479068129721178743.tmp/core.a(main.cpp.o): In function main': C:\Users\Jacob Harris\Desktop\arduino\arduino-1.5.5\hardware\arduino\avr\cores\arduino/main.cpp:14: undefined reference to loop'

Here is my code.

#include <SoftwareSerial.h> 
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);
 
int led = 13;
 
void setup()
{
  Serial.begin(19200);
  // set up the digital pins to control
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
 
  // wake up the GSM shield
  Serial.println("powering up");
  SIM900power(); 
  SIM900.begin(19200);
  Serial.println("6.2 more sec");
  delay(6000);  // give time to log on to network.
  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
  Serial.println("Ready...");
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}

void time(int value)
{
  Serial.println("I made it here");
  Serial.println(value);
  int future=value*10UL;
  loop(future);
}
void evaluate()
  {
    static char input_line [4];
    inchar=SIM900.read();  //First char
    Serial.println("First Char");
    Serial.println(inchar);
    if (inchar=='<')
    {
        inchar=SIM900.read(); //Second char
        Serial.println("Second Char");
        Serial.println(inchar);
      if (inchar=='o')
      {
          inchar=SIM900.read();  //Third char
          Serial.println("Third Char");
          Serial.println(inchar);
        if (inchar=='n')
        {
            inchar=SIM900.read();  //fourth char
            Serial.println("Fourth Char");
            Serial.println(inchar);
          if (inchar=='>')
           {
             digitalWrite(led, HIGH);
           }
          else if (inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
          {
              input_line [1]=inchar;
              inchar=SIM900.read();  //fifth char
              Serial.println("Fifth Char");
              Serial.println(inchar);

            if(inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
            {
                input_line [2]=inchar;
                inchar=SIM900.read();  //sixth char
                Serial.println("Sixth Char");
                Serial.println(inchar);
              if (inchar='.')
              {
                  inchar=SIM900.read();  //seventh char
                  Serial.println("Seventh Char");
                  Serial.println(inchar);             
                if(inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
                {
                    input_line [3]=inchar;
                    inchar=SIM900.read();  //eighth char
                    Serial.println("Eighth Char");
                    Serial.println(inchar);

                  if(inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
                  {
                      input_line [4]=inchar;
                      inchar=SIM900.read();//ninth char
                      Serial.println("Ninth Char");
                      Serial.println(inchar);
                      digitalWrite(led, HIGH);
                      int val = (input_line [1]-'0')*1000+(input_line [2]-'0')*100+(input_line [3]-'0')*10+(input_line [4]-'0')*1;
                      Serial.println(val);
                      time(val);

                    if (inchar=='>')
                    {
                      
                      inchar=SIM900.read();//tenth
                      Serial.println("Tenth Char");
                      Serial.println(inchar);
                    }
                    
                  }
                }
              }
            } 
          }
        }
        else if (inchar =='f')
          {
            inchar=SIM900.read();  //fourth char
            Serial.println("Fourth Char");
            Serial.println(inchar);
          if (inchar=='f')
           {
            inchar=SIM900.read();  //fifth
            Serial.println("Fifth Char");
            Serial.println(inchar);
            if (inchar=='>')
              {
                digitalWrite(led, LOW);
              }
           }
          }  
      }
    }
  }
void loop(unsigned long futuremillis) 
{

  //If a character comes in from the cellular module...
  unsigned long currentmillis = millis();
  if(SIM900.available() >0) evaluate();
  if(futuremillis< currentmillis) digitalWrite(led, LOW);

}

 //SIM900.println("AT+CMGD=1,4"); // delete all SMS

You have a loop function defined as:

void loop(unsigned long futuremillis)

Why?

You must have one defined as:

void loop(void)

Pete

    mode;

This ; is wrong!.

Mark

Compilers read your code from the top of the file to the end - so look for the first error and fix it eg the misplaced ';' in one of your array dec's.

Given the speed of the IDE - verifiy your code every 5 or 10 lines.

Always auto format the code as you work. It's also a good idea to test your code as your work - test each function as you write it and remember that you should use functions not just to avoid repeating code but for blocks of code this will make your code much easier to read and debug.

Mark

Gabriel_Shell:
I have met this problem before
I found that the problem is I am using "main" as the sketch's name.
May be we cannot use "main" as a sketch name.
So I change the name, and then problem solved.

J'avais le même problème, j'avais nommer mon programme "Main" :grin:

Got the same issue, I named my program "main"...

holmes4:

    mode;

This ; is wrong!.

Mark

No, that semi-colon is terminating that long list of int declarations.

Regards,
Ray L.

            if(inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
            {
                input_line [2]=inchar;
                inchar=SIM900.read();  //sixth char
                Serial.println("Sixth Char");
                Serial.println(inchar);
              if (inchar='.')
              {

There's not a snowball's chance in hell that if the char is between '0' and '9' that is will also be equal to '.'.

Indent your code properly!

There's not a snowball's chance in hell that if the char is between '0' and '9' that is will also be equal to '.'.

Thats why he is rereading it.

if(inchar=='1' || inchar=='2' || inchar=='3' || inchar=='4' || inchar=='5'|| inchar=='6'|| inchar=='7'|| inchar=='8'|| inchar=='9'|| inchar=='0')
{
input_line [2]=inchar;
inchar=SIM900.read(); //sixth char
Serial.println("Sixth Char");
Serial.println(inchar);
if (inchar**=**'.')
{

But he is also missing another equal sign so basically he is assigning '.' to inchar, making that statement always true

in both sketches I had used a 'loop' and switched it to a 'void loop'.

loop() is a function and functions must have a return type, even if it is void. If the loop() function does not have a return type then the program will not compile. Whatever ptoblem you had it was not due to main.cpp "holding onto" the loop reference.

Dejavu:
My theory was that main.cpp was holding onto the invalid loop reference, which it was.

I agree with UKHeliBob, what the heck does "holding onto" mean?

I went in and opened main.cpp with wordpad (nothing fancy required) and I changed the only line referencing 'loop' to 'void loop'.

main.cpp properly calls loop(). It means there MUST be a function in your sketch with the signature "void loop()" in order to work properly. If you change main.cpp's call to that function in a misguided attempt to make an erroneous sketch compile, you run the risk of subverting the intended operation of the system and breaking it so that properly coded sketches won't work. This sounds like a REALLY BAD idea to me.

Think about it: the way that main.cpp calls loop() works for the many thousands of people who have written thousands (millions?) of sketches. But it doesn't work for your two sketches. Where is the most likely place for the error? In main.cpp, which is successfully used by so many, or in your two sketches? Given that, where's the most appropriate place for a fix?

I would not change any of the core files unless there was a REALLY GOOD reason to do so. Trying to fix an invalid loop() definition is not such a reason.

All I did was reformat the example code a little (I prefer Allman style) and it started. I undid my changes and it persisted.

But, I'm not going to show you my code. Help me anyway.

Not in my lifetime.

OK, let's see your reformatted code with setup() and loop() functions in it.

SamDG decided to vent a little spleen, and is no more.
I really don't like the C-word

AWOL:
SamDG decided to vent a little spleen, and is no more.
I really don't like the C-word

Thanks.