delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/06/19:36:17

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
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: <e60bcscv47h4anpc4uh48ba6g2e54omor1@4ax.com>
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> <ltj7cs0ds01vup6cfrbv0vasg0akrihe4i AT 4ax DOT com> <38C307A8 DOT 6F680858 AT myokay DOT net>
NNTP-Posting-Host: modem-12.silicon.dialup.pol.co.uk
Mime-Version: 1.0
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 <caramaith AT myokay DOT net> 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 <CppLib.h>, 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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019