A simple way to make sure this works in all files is to add this to a header (.h) file:
Code:
#ifdef DEFINE_VARS
extern int foo;
#endif
#ifndef DEFINE_VARS
#define DEFINE_VARS
int foo;
#endif
So, what does this do? You have some macro, DEFINE_VARS. If it has already been defined, you declare extern int foo. If it hasn't been defined, you define it and declare int foo. This way, foo is external for all files but one.
I hope this helps.