[Gllug] OT - GNU compiler error

John Winters john at sinodun.org.uk
Mon Apr 7 15:39:05 UTC 2008


Mick Farmer wrote:
> Dear GLLUGers,
> 
> I'm compiling a C program with the command line
> 
>     gcc -ansi -c search.c
> 
> and get the error message
> 
>     search.c:5: error: duplicate `extern'
> 
> The int debug is defined in a different file that's linked
> with this one.  As you can see, I've stripped out everything
> that's not essential.  Can anyone help with this?  I have
> other similar files that don't raise this error.
> 
> <<<<<<<<<<<<<<<<<<<<
> #include "poly.h"
> #include "search.h"
> #include "zero.h"

You'll need to show us these *.h files as well.

It's a bit odd to have the line:

extern int debug;

in a .c file.  It's natural home is in a .h file which you then include 
in the .c file where it is defined, *and* in any .c files which make use 
of it.  That way the compiler can check that everyone has the same idea 
about what kind of variable it is.

Like this:

==== File debug.h ====

extern int debug;

==== File debug.c ====

#include "debug.h"

int debug;

==== File client.c ====

#include "debug.h"

debug = 99;


HTH
John
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list