c - same struct different files -


i've got little problem. have 2 files: one.c , two.c both decler , implement struct: stacknode header files are: one.h:

 #ifndef one_h  #define one_h   typedef struct stacknode stacknode;  #endif 

two.h:

 #ifndef two_h  #define two_h   #include "one.h"   #endif 

cpp files: one.c:

 #include <stdio.h>  #include <malloc.h>  #include <string.h>  #include <stdlib.h>  #include "one.h"   struct stacknode  {    ........  }; 

two.c:

 #include <stdio.h>  #include <malloc.h>  #include "two.h"  struct stacknode  {    ........  }; 

why compile , run in linox in visual stutio says: two.obj : error lnk2005: "struct stacknode * top" (?top@@3paustacknode@@a) defined in one.obj 1>c:\users\documents\visual studio 2010\projects\exercise\debug\exercise.exe : fatal error lnk1169: 1 or more multiply defined symbols found

what can work in visual too? thank :)

the linker not structure defined twice. says object top defined twice struct stacknode * top. have define in 1 compilation unit.

two.obj : error lnk2005: "struct stacknode * top" (?top@@3paustacknode@@a) defined in one.obj


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -