   extern: conflicting types for x
  (For the record, the actual name of the variable is not "x" but is in fact something large, meaningful, and unique across all of the source files in my project.)In a header file included by two seperate source files I declare x thus:extern unsigned long int x;In one of the source files (the one that contains my main function) I define x thus (globally):unsigned long int x;In the main function, I assign it an initial value.x = 0;And in the other source file, it is used as a counter to monitor the number of times a certain function is called upon during a calculation (for profiling).The error I'm getting is this:main.c:31: error: conflicting types for ‘x’include/util.h:71: error: previous declaration of ‘x’ was hereI've often used extern to share variables across source files in the past, and it's been a long time since it's given me any trouble. I must be doing something silly, but I can't imagine what it might be?If you could suppose what it might be, I'd be very grateful. I'm not really at liberty to post much of the source code =\ as NDAs go. But this seems such a simple conflict; the solution must be easy. I hope.Thanks in advance for your time.   
  Post the code on main.c line 31, and util.h line 71.   ;  Is there more to the error message?  If I do something like:extern long blarg;int blarg;I get:main.cpp|54|error: conflicting declaration 'int blarg'|main.cpp|53|error: 'blarg' has a previous declaration as `long int blarg'|main.cpp|54|error: type mismatch with previous external decl of `int blarg'|main.cpp|53|error: previous external decl of `long int blarg'|main.cpp|54|error: declaration of `int blarg'|main.cpp|53|error: conflicts with previous declaration `long int blarg'|Possible things are typoes, re-using a variable name, or trying to use x somewhere before it is declared (ie, you do x = 0; somewhere higher up than you do the "unsigned long int x"is main.c:31 where you do x = 0; or is it where you do "unsigned long int x"?  Which line is above which?[Edited by - rethan on May 5, 2009 12:10:31 AM];Quote:Original post by rethanYou cannot do this since this is conflicting information for the compiler.  (The header says that x is found in another source file, and then you say that x is right here.)Sorry, that's not right.  To quote from MSDN:Quote:http://msdn.microsoft.com/en-us/library/0603949d(VS.80).aspxThe extern keyword declares a variable or function and specifies that it has external linkage (its name is visible from files other than the one in which it's defined). When modifying a variable, extern specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends). The variable or function may be defined in another source file, or later in the same file. Declarations of variables and functions at file scope are external by default.As far as the error goes, make sure you aren't accidentally declaring some variable named 'x' in the header (do a search for that variable name in the header file to make sure).  That's all I can suggest without seeing more code.   ;Quote:Original post by MikeTacularQuote:Original post by rethanYou cannot do this since this is conflicting information for the compiler.  (The header says that x is found in another source file, and then you say that x is right here.)Sorry, that's not right.  To quote from MSDN:Quote:http://msdn.microsoft.com/en-us/library/0603949d(VS.80).aspxThe extern keyword declares a variable or function and specifies that it has external linkage (its name is visible from files other than the one in which it's defined). When modifying a variable, extern specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends). The variable or function may be defined in another source file, or later in the same file. Declarations of variables and functions at file scope are external by default.As far as the error goes, make sure you aren't accidentally declaring some variable named 'x' in the header (do a search for that variable name in the header file to make sure).  That's all I can suggest without seeing more code.You're right, I had a brain fart which is why I updated my post, sorry for the confusion!   ;  Hey all; thanks for the replies.main.c at 31 is justunsigned long int g_calls_to_divrem_core;and util.h at 71 is justextern unsigned long int g_calls_to_divrem_core;What is really frustrating about this is that I have another variable declared in precisely the same way in precisely the same places and it works. That implies I have some other variable somewhere named g_calls_to_divrem_core...but grepping over my entire codebase clearly shows that is not the case.Maybe I'll just abandon that name...but I really wish I knew what the cause behind this was so I could avert it in the future. And, you know, enhance my understanding of the black magic that is raw C.   ;  Hmm... any chance you can post the output of a grep across your code for that variable name?   ;  On Apoch's request I am posted a grep over my code, which now compiles without error as I've commented out all instances of g_calls_to_divrem_core.Note that the only files where g_calls_to_divrem_core are not remarked out are backups (ending with a ~, because that's what emacs does).> grep -r calls_to_divrem_core *main.c://unsigned long int g_calls_to_divrem_core;main.c://g_calls_to_divrem_core = 0;common/mp.c~:if (g_calls_to_divrem_core < 50000000)common/mp.c~:  g_calls_to_divrem_core++;common/mp.c~:if (g_calls_to_divrem_core >= 50000000 && g_samples_taken < 300000)common/mp.c://if (g_calls_to_divrem_core < 50000000) // too big? too small?common/mp.c://  g_calls_to_divrem_core++;common/mp.c://if (g_calls_to_divrem_core >= 50000000 && g_samples_taken < 300000)include/shpapi.h~:  extern unsigned int g_calls_to_divrem_core;include/util.h~:  extern unsigned int g_calls_to_divrem_core;include/shpapi.h://  extern unsigned int g_calls_to_divrem_core;It's a little clearer with the back-up files omitted:main.c://unsigned long int g_calls_to_divrem_core;main.c://g_calls_to_divrem_core = 0;common/mp.c://if (g_calls_to_divrem_core < 50000000) // too big? too small?common/mp.c://  g_calls_to_divrem_core++;common/mp.c://if (g_calls_to_divrem_core >= 50000000 && g_samples_taken < 300000)include/shpapi.h://  extern unsigned int g_calls_to_divrem_core;This is slowly approaching weirdest error ever. Maybe it's built into an object file or something (I don't see how that could be the issue...but I'm way out of ideas).   ;  You have the variable declared as an integer in the header and defined as a long for the definition. That might be a bit of a problem ;)   ;  Ha! So I do.I'd rather be a noobcake than a victim of some bizarreness I can't identify. Just goes to show you how long I've been staring at this code.Thanks everyone for your help and thoughts.Cheers,Steve   