www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/10/03/03:06:55

Date: Tue, 3 Oct 1995 08:11:33 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Chris A. Rodgers" <car AT wwa DOT com>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: can't compile c++

On Mon, 2 Oct 1995, Chris A. Rodgers wrote:

> Hi all!  In short, I installed djgpp and it compiled hello.c from the
> samples directory just fine, but when I try a simple c++ program, I get
> the following error:
> 
> myfirst.cc(.text+0x2e): undefined reference to `cout'
> myfirst.cc(.text+0x33): undefined reference to `ostream::operator<<(char const *
> )'
> myfirst.cc(.text+0x40): undefined reference to `cout'
> myfirst.cc(.text+0x45): undefined reference to `ostream::operator<<(char const *
> )'
>
> [snip] 
>
> E:\DJGPP\SRC\cis_230\testbed1>gcc -v myfirst.cpp

Short answer: add `-lgpp -lm' to the end of your command line.

Long answer: you did download the FAQ (faq102.zip), but probably didn't 
try to search it.  The FAQ has this entry at section 8.8:

8.8   Q: When I compile my program, the linker complains about mathematical
         functions, although I did #include <math.h>.
      Q: The linker complains it cannot find cprintf function.
 -->  Q: Why do I get so many unresolved symbols when linking C++ programs?
      A: By default, gcc instructs the linker to only look in two libraries:
         libgcc.a and libc.a.  Some functions aren't included there, so the
         linker can't find them.  For math functions, like sin() and exp(),
         append ``-lm'' to the gcc command line; for pc-specific
         functions, like cputs() and cprintf() append ``-lpc''; to use C++
         classes append ``-lgpp''.  GPL library routines, like obstack and
         regex packages are in libgpl.a library; append ``-lgpl'' to use
         them.

         Note that some C++ classes use math routines, so the -lm should
         be given after the -lgplus.

There are more sections after this which deal with related problems; 
please read them and save yourself a lot of pain.

- Raw text -


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