www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/19/01:43:06

Date: Fri, 19 Aug 94 00:04:45 EDT
From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock)
To: OKRA AT max DOT tiac DOT net
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: libraries
Reply-To: babcock AT cfa DOT harvard DOT edu

>   So let me restate the problem.  In order to compile graph.c to a .o 
> file, it needs access to the variables.  In order to compile a program 
> that uses graph.c, it _also_ needs access to the variables.  So I end up 
> with two definitions of each variable used and, thus, no executable program.

Your variables need to be declared extern everywhere but one place.  One way
of doing this is to make the .h files look like:
   #ifndef EXTERN
   #define EXTERN extern
   #endif
   EXTERN int foo;
   ...
Before the #include in your main routine, insert
   #define EXTERN

- Raw text -


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