collect2 / ld giving strange errors with undefined virtual functions
Smilodon
smilodon@niksula.hut.fi
Thu Mar 25 17:10:00 GMT 1999
EGCS version 2.91.66, Linux/glibc2, GNU binutils 2.9.1
Whether this is a bug and if it is in collect2, ld, or egcs, I am not
sure. When a constructor is declared inline and a virtual method and/or a
destructor is declared but not defined anywhere, the linker complains
about an undefined reference to the constructor in the code trying to
construct an instance of the class.
Here is one instance:
-- snip of models.H --
class MDL_piece
{
public:
inline
MDL_piece(int md_index, int vxs_, int tris_)
: vxs(vxs_), tris(tris_)
{}
inline
MDL_piece()
: exists(false), mod_index(0), vxs(0), tris(0)
{}
virtual ~MDL_piece();
virtual void view_from( placement &eye );
virtual bool intersect(ray &, obj_hit_t &);
virtual bool collide( vector &, value );
virtual vector& location() { return pos.loc; }
virtual MDL_piece& next();
// ...
}
-- snip of models.C - a couple of routines commented out to lure
out the 'bug':
bool
MDL_piece::intersect( ray &r, obj_hit_t &blast )
{
triangle * T = tris.first();
while ( tris.good(T) ) {
if ( triangle_intersect( *T,
vxs[T->o].loc,
r.origin, r.delta,
blast.loc )) {
return true;
}
++T;
}
return false;
}
// bool
// MDL_piece::collide( vector & other_loc, value rad )
// {
// value D = vdistsq( other_loc, pos.loc );
// return ((rad*rad + bounding_radius*bounding_radius) < D);
// }
void
MDL_piece::view_from( placement &eye )
{
eye = (eye * pos);
}
// MDL_piece::~MDL_piece()
// {
// }
// MDL_piece &
// MDL_piece::next()
// {
// return *this;
// }
Build log:
import/fl_4tex.o: In function `extract_4tx_objs(MDL_piece **, texdata
const *)':
import/fl_4tex.o(.text+0x2425): undefined reference to
`MDL_piece::MDL_piece(void)'
collect2: ld returned 1 exit status
make: *** [test2files] Error 1
---
CFLAGS = -g -Wall -ansi
---
This seems to happen when
1) the class constructor is declared inline, and
2) one or more virtual methods are undefined.
While this error is a result of an obvious defect in the code being
compiled, it is still rather confusing to get a message about a missing
constructor when it is something else that is missing. :)
-- Smilodon.
More information about the Gcc-bugs
mailing list