GENERAL: HEADER FILE IS BEING PROCESSED MORE THAN ONCE
Information in this article applies to:
I have written the following header file 'header.h' and included it in several .c source files:
#ifndef header #define header unsigned char x; #endif
When I build my project, the linker complains that x is being redefined, however, I thought the preprocessor directives used would ensure the file is only processed once.
The scope of the '#define header' is limited to each source file. So for each source file, header is undefined and the variable x is redefined. The linker then sees x defined in more than one object file and complains.
There are two solutions to this problem.
For example, you may create a file called 'globals.c' containing:
unsigned char x;
Then create a header file called 'globals.h' containing:
extern unsigned char x;
Simply include the header file 'globals.h' in each .c source file.
The following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Saturday, July 9, 2005
of your data.