From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: odd compiler error in DJGPP... Date: Tue, 07 Mar 2000 22:44:34 +0000 Organization: Customer of Planet Online Lines: 36 Message-ID: References: <38C17CB3 DOT BCC06203 AT myokay DOT net> <38C1A7B4 DOT AF973AB7 AT myokay DOT net> <1rs6csgsc9mcr6f4sp406tapu7jlc7n7ho AT 4ax DOT com> <38C23F28 DOT FD812219 AT myokay DOT net> <38C307A8 DOT 6F680858 AT myokay DOT net> NNTP-Posting-Host: modem-12.silicon.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg2.svr.pol.co.uk 952383249 20866 62.136.13.12 (6 Mar 2000 22:54:09 GMT) NNTP-Posting-Date: 6 Mar 2000 22:54:09 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com caramaith wrote: > I get this when just doing the normal > > gcc -o CppLibTest.exe CppLibTest.cpp That line tries to do a complete *compile&link* in a *single* command. CppLibTest.cpp calls functions which are defined in CppLib.cpp, this is ok because you already tell the compiler about these when you #include , so the compile phase goes without a hitch. But when gpp attempts to link your code (that means tying up the function calls with the functions) it can't find the code in CppLib and as far as gpp is concerned it doesn't exist! This is where the undefined references come from. You will see similar errors if you compile C++ code with gcc because it does not link in the C++ library by default. Because you have more than one source file you must do the compiling and linking separately like this: gpp -Wall -c CppLibTest.cpp gpp -Wall -c CppLib.cpp gpp -g CppLibTest.o CppLib.o -o CppLibTest The first two lines compile the source files (.cpp) to object files (.o) and the last line links the two object files together with the C++ library (libstdcxx) to make an executable (.exe). I suggest to use the dir command between each line so that you can see for yourself what happens. I hope that this and the other replies help to explain what you are doing wrong. A Good Thing to do now would be to digest the first few sections of the FAQ so you understand how to compile and link, and try to find where in Bruce Eckel's book he explains this.