Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mailrus!uwm.edu!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!aero!aerospace.aero.org!slewis From: slewis@aerospace.aero.org (Steven Lewis) Newsgroups: comp.sys.mac.programmer Subject: Re: Link error : multiply defined variables in THINK C Message-ID: <80424@aerospace.AERO.ORG> Date: 8 Aug 90 17:06:23 GMT References: <12725@june.cs.washington.edu> Sender: news@aerospace.aero.org Reply-To: slewis@antares.UUCP (Steven Lewis) Organization: The Aerospace Corporation, El Segundo, CA Lines: 24 In article <12725@june.cs.washington.edu> ginting@fred.cs.washington.edu (Eka Namara Ginting) writes: > > I'm writing a program that has two source files (.c) that import > a common .h file. This .h file includes another .h file that contains > some variable declarations. When I try to run this program, THINK C > compiler complains with "link failed : multiply defined variables" and > gives me the list of variables that I declared in the second .h file > (the one included by the other .h file). These variables are of type > unsigned long, not initialized, nor of class static. > Did you declare the variables extern in the header file?? failure to do so will cause definition in both files. another trick is to do something like this: #undef EXTERN /* make sure this not done earlier */ #ifdef FOO /* something defined in only one file */ #define EXTERN /* This actually declares the variable */ #else #define EXTERN extern /* only make extern call */ #endif FOO Now declare all variables EXTERN also make sure your #ifndef statements are done correctly while THINK_C