Header files aren't meant for declaring variables; it's actually against the ANSI standard. What you need to do is put your global variables in a C file; perhaps globals.c...then create a header file. Title the header file with the same base name, in this case globals.h. Globals.h should look like this:
#ifndef _GLOBALS_H_ // i use _BASENAME_H_ use whatever you like
#define _GLOBALS_H_ // this prevents multiple includes
extern int nMyGlobal;
extern ...
#endif
Then in my C files:
#include "globals.h" // this can be used in ALL files, you can even include it in globals.c itself
nMyGlobal = 10;
If you stick to this convention, you will never have this kind of problem again no matter what ANSI C compiler you are using. Many people don't know it, but you can use extern even if the variable or function is in the same module without any penalties. All it does is it tells the compiler that the reference will be resolved at link time as opposed to compile time.
View this message in context: Re: (no subject)
Sent from the AVR - gcc forum at Nabble.com.