Link Error - With simple variable declaration?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link Error - With simple variable declaration?

1,395 Views
PopsStack
Contributor I
I am trying to declare a variable in a module and reference it in my main () routine - should be straight forward but am getting the following link error:
 
Link Error : Multiply-defined: "LED_Status in Int_Handlers.c
Previously defined in main.c
 
I am using the variable LED_Status in the main routine and setting it in the interrupt routine for the PIT Timer.

unsigned char LED_Status = FALSE; // Declared just above main
 
int main()
{
  int i;
  char a;
  mcf5222x_init(); // As well as all other initialization stuff
  if (!LED_Status) etc etc etc....
.
.
.etc etc
}
 
This is in the Interrupt handling module.

extern unsigned char LED_Status = FALSE;
__interrupt__ void PIT0_handler (void);
__interrupt__ void PIT0_handler (void)
 
{
  LED_Status = !LED_Status;
  MCF_PIT0_PCSR  |= MCF_PIT_PCSR_PIF; // Reset by setting PIF
}
 
I tried declaring it in a .h file. Still the same problem.
 
Am I doing something stupidly obvious and stupidly wrong??
 
Many thanks
 
PS
Labels (1)
0 Kudos
2 Replies

365 Views
CompilerGuru
NXP Employee
NXP Employee
Don't add an initialization value for a declaration,
so instead:
>extern unsigned char LED_Status = FALSE;
try
extern unsigned char LED_Status;

Also I would suggest to place the "extern unsigned char LED_Status;" into a header file main.h and include that one in
both main.c and into your interrupt handler module.

Daniel


0 Kudos

365 Views
PopsStack
Contributor I
Hi
 
Many thanks - amazing how one can stare at the obvious for hours and not see it!
 
Regards
 
Nic
0 Kudos