Odd linker error concerning virtual function

steffend@lamar.colostate.edu steffend@lamar.colostate.edu
Fri Aug 20 13:50:00 GMT 1999


GNUrus,

I've run into an odd error with GCC 2.95.1. The following code
reproduces the error:

class A
{
public:
  A() {} 
  virtual int clone();
};

int main()
{
  A a;
}

and the error generated is:

/tmp/ccSKB5QU.o: In function `main':
/tmp/ccSKB5QU.o(.text+0x21): undefined reference to `A::A(void)'
collect2: ld returned 1 exit status

The problem seems to be that I have a virtual function with no defined
body. While I can see why the compiler might be upset about not having
an implementation of A::clone(), it seems odd that it complains about
a missing constructor.

I compiled with no extra flags:

c++ -o newtest newtest.C

For reference, I'm on a PentiumII machine running RedHat 5.1, and gcc -v
produces

Reading specs from /opt/gcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/specs
gcc version 2.95.1 19990816 (release)

Thanks!!

--------------------------------------------------------------------------
Dave Steffen                      Wave after wave will flow with the tide
Dept. of Physics                    And bury the world as it does
Colorado State University         Tide after tide will flow and recede
steffend@lamar.colostate.edu        Leaving life to go on as it was...
							- Peart / RUSH
"The reason that our people suffer in this way.... 
is that our ancestors failed to rule wisely".   -General Choi, Hong Hi








More information about the Gcc-bugs mailing list