Never declare variables in a header file. You can extern the variables, but never declare them. If you declare the variable in the header file, the compiler tries to create the variable each time it reads the header file.
Here's an example of what you should do:
Code:
foo.c:
int myvar;
void foo(void)
{
myvar = 2;
}
bar.c:
extern int myvar;
void bar(void)
{
printf("myvar %d\r", myvar);
}
Alternatively you could get rid of the 'extern int myvar'; from bar.c and move it to a header file that you include in any c file that uses myvar.
Code:
foo.c:
#include "globals.h"
int myvar;
void foo(void)
{
myvar = 2;
}
bar.c:
#include "globals.h"
void bar(void)
{
printf("myvar %d\r", myvar);
}
globals.h:
extern int myvar;