Problem include c file

i have write 2 .c file and 2 .h file

the code is:

main (.c)

/**
*      Wally Robot 
*
*      Angelo Facondini      
*/

//#include "WProgram.h"
#include "wally_main.h"
#include "baseMovement.h"


//prototipe
int goAhead( int dist, int vel);
int goBack( int dist, int vel);
int turnLe( int degree);
int turnRi( int degree);



 void setup()   {       
   
    Serial.begin(9600); // inizialize serial port

    
   // initialize the digital pin as an output:
  
   //motor 1
   pinMode(motL_1, OUTPUT);     
   pinMode(motL_2, OUTPUT); 
//    pinMode(motL_3, OUTPUT);     
//    pinMode(motL_4, OUTPUT);
   
   //motor2
   pinMode(motR_1, OUTPUT);     
   pinMode(motR_2, OUTPUT); 
//    pinMode(motR_3, OUTPUT);     
//    pinMode(motR_4, OUTPUT);
   
   //sensor
   pinMode(sensFw, INPUT);     
   pinMode(sensRw, INPUT); 
  // pinMode(senseLe, INPUT);     
  // pinMode(senseRi, INPUT); 
 }


 void loop()                     
 {
   int state = WALK_TO_S;

   switch( state)
   {
     case IDLE_S :
     break;
     
     case WALK_TO_S :
       //reach(x,y);
       int ret;
       
      ret = goAhead( 100,1); //go forw 100cm with a velocity of 1cm/s
      
      if(ret!=0)
        turnRi(90); //turn 90°
     break;
     
     case SERIAL_S:
       if ( Serial.available()) //chek if there's data
      {
        int lettura = 0;
        lettura = Serial.read();
        
        if(lettura == FORW_S)
          goAhead( 2,1);      //go forwarder 2cm at 1cm/s
        if(lettura == REW_S)
          goBack( 2,1);      //go back 2cm at 1cm/s
        if(lettura == STOP_S)
            resetOutMot();    //not useful now
        if(lettura == RIGHT_S)
          turnRi(90);
        if(lettura == LEFT_S)
          turnLe(90);
      }
      break;
   }
 }


/**
*      Go forwarder
*      dist (cm)
*      vel (cm/s)
*/
int goAhead( int dist, int vel)
{
  int cicle;
  int waitTime;
  
  cicle  = dist * CICLE_DIST_RATIO;      //dist--> cicle
  waitTime = (vel * 250) / CICLE_DIST_RATIO;       //time wait between phase  --> (vel * 1000) / ( 4 * CICLE_DIST_RATIO )
  
  if(
      moveMot(MOT_L,cicle, waitTime,0)!=0 ||
      moveMot(MOT_R,cicle, waitTime,0)!=0 
    ) //there is a obstacle
    return -1;
  
  return 0;
}


/**
*      Go back
*      dist (cm)
*      vel (cm/s)
*/
int goBack( int dist, int vel)
{
  int cicle;
  int waitTime;
  
  cicle  = dist * CICLE_DIST_RATIO;      //dist--> cicle
  waitTime = (vel * 250) /  CICLE_DIST_RATIO;      //time wait between phase  --> (vel * 1000) / ( 4 * CICLE_DIST_RATIO )
  
  if(
      moveMot(MOT_L,cicle, waitTime,1)!=0 ||
      moveMot(MOT_R,cicle, waitTime,1)!=0
    ) //there is a obstacle
    return -1;
  
  return 0;
}


/**
* Turn Left
*
*/
int turnLe( int degree)
{
  int circ,dist,cicle,ret;
  
  circ = (2*DIST_WHELLS *314)/100;  //(2*dist_whells*3.14)
  dist = (360/degree)*circ;
  cicle  = dist * CICLE_DIST_RATIO;
  
  ret = moveMot(MOT_R,cicle/2,WAIT_TIME_TURN,0);
  ret = moveMot(MOT_L,cicle/2,WAIT_TIME_TURN,1);
  
}


/**
* Turn Right
* 
*/
int turnRi( int degree)
{
   int circ,dist,cicle,ret;
  
  circ = (2*DIST_WHELLS *314)/100; //(2*dist_whells*3.14)
  dist = (360/degree)*circ;
  cicle  = dist * CICLE_DIST_RATIO;
  
  ret = moveMot(MOT_L,cicle/2,WAIT_TIME_TURN,0);
  ret = moveMot(MOT_R,cicle/2,WAIT_TIME_TURN,1);
}

baseMovement.c

/*
*       *****Low comand for bipolar stepper motor******
*
*/



#include "baseMovement.h"
#include "wally_main.h"



int forwSeq[4][2] = {
                {0,1},
                {1,1},
                {1,0},
                {0,0}
               };

int rewSeq[4][2] = {
                {0,0},
                {1,0},
                {1,1},
                {0,1}
               };
               
int moveMot(int mot, int cicle, int waitTime, int rot)
{
    int count=0;
    int i;
    
    //abbasso tutte le uscite
    resetOutMot();
    
      switch(mot){
          
          case MOT_L:            //Left Motor
            for(count=0;count++;count<=cicle)
            {
            for(i=0;i<4;i++)
            {
                  if(rot==ROT_FW)
                  {
                digitalWrite(motL_1, forwSeq[i][0]);
               // digitalWrite(motL_2, forwSeq[i][1]);
                  }
                  else
                  {
                digitalWrite(motL_1, rewSeq[i][0]);
             //   digitalWrite(motL_2, rewSeq[i][1]);
              }
                  
            }
            
            if(digitalRead(sensFw) || digitalRead(sensRw))
              return -1;
            }
            break;

          case MOT_R:            //Right Motor
            for(count=0;count++;count<=cicle)
            {
            for(i=0;i<4;i++)
            {
                  if(rot==ROT_FW)
                  {
            //    digitalWrite(motR_1, forwSeq[i][0]);
                digitalWrite(motR_2, forwSeq[i][1]);
                  }
                  else
                  {
                //    digitalWrite(motR_1, rewSeq[i][0]);
                digitalWrite(motR_2, rewSeq[i][1]);
                  }
            }
            
            if(digitalRead(sensFw) || digitalRead(sensRw))
              return -1;
            }
            break;
            
        }

        
        
 
    
    resetOutMot();
    return 0; //all ok
}


void resetOutMot()
{
  digitalWrite(motR_1, 0);
  digitalWrite(motR_2, 0);
//   digitalWrite(motR_3, 0);
//   digitalWrite(motR_4, 0);
  digitalWrite(motL_1, 0);
  digitalWrite(motL_2, 0);
//   digitalWrite(motL_3, 0);
//   digitalWrite(motL_4, 0);
}

baseMovument.h

#ifndef  BASE_MOVEMENT____H
#define  BASE_MOVEMENT____H


int moveMot(int mot, int cicle, int waitTime, int rot);
void resetOutMot();

#endif

wallyMain.h

#ifndef ROBOT____H
#define ROBOT____H


#define MOT_STEP 48 //number step/rev of motor
#define CICLE_DIST_RATIO 5 //(step/cm)
#define DIST_WHELLS 30 //distace between whells (cm)
#define WAIT_TIME_TURN 100 //wait time phase during turning
#define MOT_L 1
#define MOT_R 2
#define ROT_FW 0
#define ROT_REW 1


//serial comand
#define FORW_S 1
#define REW_S 2
#define STOP_S 3
#define RIGHT_S 4
#define LEFT_S 5


//state
#define IDLE_S 0
#define WALK_TO_S 1
#define SERIAL_S 2

/******  I/O mapping ****************/

//left motor (1)
 int motL_1 =  1; //phase 1 motor left 
 int motL_2 =  2; //phase 2 motor left
//  int motL_3 =  3; //phase 3 motor left 
//  int motL_4 =  4; //phase 4 motor left
 
 //Right motor (2)
 int motR_1 =  4; //phase 1 motor right 
 int motR_2 =  5; //phase 2 motor right
//  int motR_3 =  6; //phase 3 motor right
//  int motR_4 =  7; //phase 4 motor right
 
 //prossimity sensor
 int sensFw =  8; //prosimity forwarder
 int sensRw =  9; //prosimity back
// int sensLe =  10; //prosimity Left
// int sensRi =  11; //prosimity Right



#endif

but whe compile, there is this error:

o: In function `resetOutMot':
multiple definition of `motR_1'o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:163: first defined here
o: In function `resetOutMot':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:171: first defined here
o: In function `resetOutMot':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:163: first defined here
o: In function `resetOutMot':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:163: first defined here
o: In function `resetOutMot':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:171: first defined here
o: In function `resetOutMot':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:171: first defined here
o: In function `turnRi(int)':
o: In function `turnLe(int)':
o: In function `goBack(int, int)':
o:/tmp/build8663446853736708691.tmp/Temporary_4356_3330.cpp:131: more undefined references to `moveMot(int, int, int, int)' follow

you have any idea?

in wallymain.h, change the int as follows:

/******  I/O mapping ****************/

//left motor (1)
extern int motL_1; //phase 1 motor left
extern int motL_2 ; //phase 2 motor left

..etc. (made them all extern.)

Then, in wallymain.cpp, define them as normal: (copied from wallymain.h)

/******  I/O mapping ****************/

//left motor (1)
 int motL_1 =  1; //phase 1 motor left
 int motL_2 =  2; //phase 2 motor left
//  int motL_3 =  3; //phase 3 motor left
//  int motL_4 =  4; //phase 4 motor left

 //Right motor (2)
 int motR_1 =  4; //phase 1 motor right
 int motR_2 =  5; //phase 2 motor right
//  int motR_3 =  6; //phase 3 motor right
//  int motR_4 =  7; //phase 4 motor right

 //prossimity sensor
 int sensFw =  8; //prosimity forwarder
 int sensRw =  9; //prosimity back
// int sensLe =  10; //prosimity Left
// int sensRi =  11; //prosimity Right

Do this for all variables defined in a header file.

As-is, they get pulled into each main source file, and then the linker has duplicates to deal with.

When declaring them extern, the linker matches them up from each source file, looking externally for a reference instead of just locally.

ok thanks!
but now the output is:

o: In function `turnRi(int)':
C:\DOCUME~1\op15l\IMPOST~1\Temp\build1573.tmp/wally_main.cpp:189: undefined reference to `moveMot(int, int, int, int)'

C:\DOCUME~1\op15l\IMPOST~1\Temp\build1573.tmp/wally_main.cpp:190: undefined reference to `moveMot(int, int, int, int)'

o: In function `goAhead(int, int)':
C:\DOCUME~1\op15l\IMPOST~1\Temp\build1573.tmp/wally_main.cpp:126: undefined reference to `moveMot(int, int, int, int)'

don't find moveMot, I have try to put extern in baseMovement.h:

extern int moveMot(int mot, int cicle, int waitTime, int rot);
extern void resetOutMot();

but nothing...

solved with extern "C"

thaks