Path: chuka.playstation.co.uk!tjs From: tjs@cs.monash.edu.au (Toby Sargeant) Newsgroups: scee.yaroze.programming.gnu_compiler Subject: Re: Including stuff Date: 10 Dec 1998 04:59:28 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 46 Message-ID: References: <74nale$6o65@scea> NNTP-Posting-Host: longford.cs.monash.edu.au X-Newsreader: slrn (0.9.4.3 UNIX) On Wed, 9 Dec 1998 21:28:07 -0500, Antony Arciuolo wrote: >I want ot make a trig look-up table, so I do it, put the definition of the >array in a header like so: > >short PSXTrigLUT[361] = { >0, 71, 142, 214, 285, >356, 428, 499, 570, 640, >711, 781, ..., 0 // just to save space in this post >}; > >I compile trig.c that includes trig.h to get trig.o, but when I try to link >this to the rest of my program, I get the error "multiple definition of >'PSXTrigLUT'" > >Does anyone know why this is and how to fix it... this only seems to happen >on explicity set arrays. It's happening because when main.c and trig.c include trig.h, each .o file gets it's own copy of PSXTrigLUT. When the .o files are combined into a single executable, you get multiple definition errors. One way to get around this is to have the definition of PSXTrigLUT in trig.c, and in trig.h, have: extern short PSXTrigLUT[361]; which tells files including trig.h that PSXTrigLUT is defined somewhere in another source file. An external reference is generated, and resolved when you link. The other way is to declare PSXTrigLUT static, but this means that you end up with multiple copies of the table, which is probably not what you want. If you want to keep the definition of the table in a header, then: #ifdef __TRIG_H_IMPL__ short PSXTrigLUT[361]={...}; #else extern shotrt PSXTrigLUT[361]; #endif and then in trig.c only: #define __TRIG_H_IMPL__ #include "trig.h" Toby.