www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/09/26/06:42:41

Date: Tue, 26 Sep 1995 17:19:20 +22305931 (WAUST)
From: Ron Grunwald <rgrunwal AT bluering DOT cowan DOT edu DOT au>
Subject: Re: Problems with linking of pure virtual functions
To: Wim Verhaegen <verhaege AT esat DOT kuleuven DOT ac DOT be>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

I have tried compiling and linking your source code
under my setup of djgpp v1.12m4, and it worked well. Below is a 
screen dump of that session:

C:\GPP$gcc -v -g -o pvf pvf.cc -lgpp
Reading specs from c:/djgpp/lib\specs
gcc version 2.6.3
 c:/djgpp/bin\cpp.exe -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplu
s -D__GNUC_MINOR__=6 -Dunix -Di386 -DGO32 -DMSDOS -D__unix__ -D__i386__ -D__GO32
__ -D__MSDOS__ -D__unix -D__i386 -D__GO32 -D__MSDOS -g pvf.cc c:/tmp\cc012992
GNU CPP version 2.6.3 (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
 c:/djgpp/cplusinc
 c:/djgpp/include
 /usr/local/lib/g++-include
 /usr/local/include
 /usr/local/go32/include
 /usr/local/lib/gcc-lib/go32/2.6.1/include
 /usr/include
End of search list.
 c:/djgpp/bin\cc1plus.exe c:/tmp\cc012992 -quiet -dumpbase pvf.cc -g -version -o
 c:/tmp\cca12992
GNU C++ version 2.6.3 (80386, BSD syntax) compiled by GNU C version 2.6.3.
 c:/djgpp/bin\as.exe -o c:/tmp\ccb12992 c:/tmp\cca12992
 c:/djgpp/bin\ld.exe -o pvf c:/djgpp/lib\crt0.o -Lc:/djgpp/lib c:/tmp\ccb12992 -
lgpp -lgcc -lg -lc -lgcc

C:\GPP$
C:\GPP$go32 pvf
go32 version 1.12.maint3 Copyright (C) 1994 DJ Delorie
The rectangle Squary has height 3 and width 2
Its area is 6 and its perimeter 10

Done.

C:\GPP$


I'm not sure why it's not working for you, except to suggest that 
perhaps there are mixed versions of libs. being used. You probably
don't want to hear this, but you might have to reinstall DJGPP to
get around the problem.


Regards, Ron.



> 
> I'm having a problem with the linking of object code when I use
> pure virtual functions. I tried the following little program:
> 
> // Start of test program
> 
> #include <iostream.h>
> #include <_string.h>
> 
> class Shape
> {
> public:
>   Shape() { n = "None"; }
>   String& name() { return n; }
>   const String& name() const { return n; }
>   virtual double area() const = 0;
>   virtual double perimeter() const = 0;
> private:
>   String n;
> };
> 
> class Rectangle : public Shape
> {
> public:
>   Rectangle() { h = w = 0; }
>   double area() const { return h * w; }
>   double perimeter() const { return 2 * (h + w); }
>   double& height() { return h; }
>   double height() const { return h; }
>   double& width() { return w; }
>   double width() const { return w; }
> private:
>   double h;
>   double w;
> };
> 
> int
> main(void)
> {
>   Rectangle rect;
>   rect.name() = "Squary";
>   rect.width() = 2;
>   rect.height() = 3;
>   cout << "The rectangle " << rect.name() << " has height " << rect.height() << " and width " << rect.width() << endl;
>   cout << "Its area is " << rect.area() << " and its perimeter " << rect.perimeter() << endl;
> 
>   cout << "\nDone.\n";
>   return 0;
> }
> 
> // End of test program
> 
> I have no problems with compiling this source code, but when I try to
> link the object code into an executable, I get the following messages:
> 
> 	test.cc(.text+0x25c): undefined reference to `__pure_virtual'
> 	test.cc(.text+0x264): undefined reference to `__pure_virtual'
> 
> When I checked the contents of libgpp.a with strings, I did find some
> references to '___pure_virtual', with one additional underscore!
> 
> So, I'd like to know how I have to solve this. Should I tell the compiler
> in some way to use an additional underscore, or am I using the wrong
> compiler or library ? (I'm using GCC 2.6.8 and LIBG++ 2.6.2).
> 
> 
> --
> Wim Verhaegen                       |  All theory is grey, my friend,
> Dept. of Electrical Engineering     |  And green the golden tree of life.
> KU Leuven, Belgium                  |
> wim DOT verhaegen AT esat DOT kuleuven DOT ac DOT be   |                              Goethe



 ********************************************************************
 | Author.............. Ron Grunwald                                | 
 | Internet............ rgrunwal AT bluering DOT cowan DOT edu DOT au              |
 | Phone............... (09)273 8027 or (09)273 8468                |
 |------------------------------------------------------------------|
 | Department.......... Computer Operations and Systems Management  |
 | Division/Faculty.... Information Technology                      | 
 | Institute........... Edith Cowan University, Churchlands         | 
 | Location............ Perth, Western Australia                    |
 ********************************************************************
 "I don't have any solution but I certainly admire the problem!"



- Raw text -


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