delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/28/23:36:29

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199703290427.AA038159623@typhoon.rose.hp.com>
Subject: Re: Multiple-file problem
To: deltaman AT swipnet DOT se
Date: Fri, 28 Mar 1997 20:27:03 PST
Cc: djgpp AT delorie DOT com
In-Reply-To: <333C3C43.7216@geocities.com>; from "Deltaman" at Mar 28, 97 10:46 pm

 
> In 'somefunc.c' I include 'header.h' and 'mainprog.c' and in
> 'mainprog.c' I include 'header.h'. It compiles perfectly (in RHIDE) but
> when I links it I get the error messages:
> 
> mainprog.c(a number)    Error: multiple definition of <function>
> somefunc.c(same number) Error: first defined here
> 
> This happens with all functions (even main) in 'mainprog.c'. What should
> I do to make it work?

As people in comp.lang.c love to point out you should use int main not
void main.

But, onto your problem.  I think in general there is never a reason
to #include a C file.  You are compiling the same source twice 
which causes the linker to complain when it sees two copies of everything.

Your .h file should contain the following.

Function prototypes
Extern variable declarations
#defines
#includes

Just include this and you should be fine.

Andrew

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019