struct.h:
#ifndef _STRUCT_H #define _STRUCT_H int i; #endif
#include "struct.h" void main(void) { i = 1; }
"If the only files in your project are main.c and struct.h, then where did struct.obj come from?" Maybe he compiled struct.h - if you add a header to a uVision Project, it will get compiled unless you uncheck the 'Include in Target Build' option for the file. "It certainly looks like two OBJ files are being linked together, and both of them contain a definition for 'i'." Yes, if he did compile struct.h he would end up with a struct.obj containing a definition of i! "It is safest to make all variable declarations in '.h' files use extern, and then only actually declare [sic] the variable (without extern) inside one (and only one) '.c' file." This is where we need to take great care to distinguish between definitions and declarations: A declaration simply informs the Compiler about an identifier; it creates no code and allocates no memory; A definition actually provides the code to implement a function, or allocates the storage space for a variable. Therefore, in general, declarations should go in headers and definitions in '.c' files - and multiple definitions in the same scope are not allowed. (BTW: This is all standard 'C' stuff; nothing specifically to do with Keil.)
uncheck the 'Include in Target Build' option for the file. good suggestion At the end,thanks to everybody.