From: jxh AT cs DOT wustl DOT edu (James Hu) Newsgroups: comp.os.msdos.djgpp,comp.lang.c Subject: Re: Can't get external variables to work!?? Date: 7 Feb 1998 16:20:53 GMT Organization: Washington University in St. Louis Lines: 40 Message-ID: References: <34DC7457 DOT 6A0A7521 AT iafrica DOT com> NNTP-Posting-Host: lambada.cs.wustl.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Sat, 07 Feb 1998 16:48:55 +0200, Bruce Merry (the Almighty Cheese) wrote: >c_types.h: >typedef unsigned char byte; > >kbd.h: >extern byte keys[128]; > >program.c: >#include "c_types.h" >#include "kbd.h" >/* stuff with the keys array */ > >kbd.c: >#include "c_types.h" >static volatile byte keys[128]; >/* code for keyboard handling */ > >Basicly, all the source files compile into objects fine, but at link >time the error 'undefined reference to keys' multiple times. What am I >doing wrong (I'm using DJGPP 2, BTW). The problem is that in kbd.h you are declaring that there is some global variable with external linkage named keys to be used, and program.c uses this variable. However, in kbd.c, you are have defined keys to be a static variable, which implies that it does not have external linkage. If you are counting on program.c being able to manipulate the variable keys that is defined in kbd.c, there is no way of doing so. Removing the keyword static from your definition of keys in kbd.c should solve your problem, assuming that is the variable you intended program.c to be able use. This problem could have been diagnosed if you had #include'd kbd.h into kbd.c. -- James C. Hu Computer Science Doctoral Student http://www.cs.wustl.edu/~jxh/ Washington University in Saint Louis >>>>>>>>>>>>> I use *SpamBeGone*