Path: utzoo!attcan!uunet!husc6!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: Help needed with #include problems Message-ID: <1114@mcgill-vision.UUCP> Date: 18 May 88 08:23:48 GMT References: <28400001@ntvax> Organization: McGill University, Montreal Lines: 38 Posted: Wed May 18 04:23:48 1988 In article <28400001@ntvax>, john@ntvax.UUCP writes: > I am using Turboc 1.5 and am having problems linking files. I am > writing a large application (over 64k) and am having trouble breaking > up the file. [...] The compile goes ok but the linker gives me the > following error - "variable name here" is duplicated in module > "source module name here". It sounds as though you have run into the difference between the "def/ref" model of shared variables and the "common" model. The "common" model is the one UNIX has historically used; in this one, a variable can be defined in multiple files, as long as it is initialized at most once. In the "def/ref" model, a variable must be defined exactly once. Definition-by-example of terms: reference extern int i; definition int i; initialization int i = 5; Under UNIX, you could have multiple definitions and the loader would merge them, provided at most one of them was initialized. On other systems (apparently Turbo 1.5 falls into this category), we have the "def/ref" (definition/reference) model, where only one definition is permitted and other files must contain merely references. The K&R definition of C permits either model; presumably dpANS C does as well, though you would do well to use just the def/ref model when writing new code, because it works on both sorts of systems. Your header file should have externs; each variable must have exactly one definition, somewhere in one of the C files. (Which C file defines which variable doesn't matter from the linker's point of view, though good style of course says they should be grouped reasonably. I generally have one file which contains nothing but variable definitions.) der Mouse uucp: mouse@mcgill-vision.uucp arpa: mouse@larry.mcrcim.mcgill.edu