From: "Willem Duminy" Subject: Re: and another thing... Newsgroups: comp.os.msdos.djgpp References: Message-ID: <01bea807$27526020$d7cb1fac@wduminy.mck.co.za> X-Newsreader: Microsoft Internet News 4.70.1155 NNTP-Posting-Host: s160-2.mck.co.za Date: 27 May 1999 08:07:16 +0200 X-Trace: 27 May 1999 08:07:16 +0200, s160-2.mck.co.za Lines: 67 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Make foo extern in header.h and define it in h.cc See below. The problem is that two modules includes your header, and both define foo. The directives ensures that you cannot include the same source more than once pre module. It has no affect during the linking process. **************** email: wduminy AT bigfoot DOT com web: http://www.bigfoot.com/~wduminy *************** Mark Phillips wrote in article ... > > Why should I get this: > > Compiling: h.cc > no errors > Compiling: main.cc > no errors > Creating: test.exe > Error: main.o(.data+0x0):main.cc: multiple definition of 'foo' > Error: h.o(.data+0x0):h.cc first defined here > > When I do this: > > // file #1 main.cc > #include "header.h" > > int main() > { > fun1(); > return 0; > } > > // file #2 h.cc > #include "header.h" < W bool foo; < W > > void fun1() > { > foo = 1; > } > > // file #3 header.h > #ifndef HEADER_H > #define HEADER_H > > void fun1(); > bool foo; < W exterm bool foo; < W > > #endif > > > Shouldn't the preprocessor directives in 'header.h' handle the multiple > declaration linking errors? > > > love > mark > >