Message-Id: <199809211254.NAA18252@rochefort.ns.easynet.net> Comments: Authenticated sender is From: "George Foot" To: KillerColt Date: Fri, 18 Sep 1998 16:20:48 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: help please Reply-to: mert0407 AT sable DOT ox DOT ac DOT uk CC: djgpp AT delorie DOT com Precedence: bulk On 17 Sep 98 at 23:02, KillerColt wrote: > What does UNDEFINED REFERENCE mean and how do I fix it? It means that you declared and used a symbol in a source file, but didn't actually define it anywhere. When the linker tried to link your object files together it found the reference to the symbol but couldn't find the definition of the symbol. For example: extern int i; int main (void) { i = 1; return 0; } In this example, the `extern' line declares that a variable `i' should exist somewhere in the program, but not necessarily in this source file. The `main' function then sets this variable to 1. This is legal, provided a definition for `i' does exist somewhere else. If you compile and link this single source file you'll get "undefined reference" because the linker never found a definition for `i'. You need to link it with a file containing a definition, i.e.: int i; This also happens with functions. If you misspell them you should first notice "implicit declaration" warnings, but if you prototype them and use them without defining them you'll get "undefined reference". In particular though, a cause of this error is forgetting to link in a library. For example, if you use Allegro's "blit" function but don't link in the Allegro library you'll get the error. Also if you write C++ code using parts of the C++ library but don't link it in (either using gxx or g++ or by explicitly linking the libraries) you'll get the same error. If you'd posted the whole text of the error it would have been possible to say which of these you are doing. -- george DOT foot AT merton DOT oxford DOT ac DOT uk