Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Compiler adds undefined symbol reference for virtual functions....

Reply
Thread Tools

Compiler adds undefined symbol reference for virtual functions....

 
 
trond.norbye@gmail.com
Guest
Posts: n/a
 
      09-29-2006
Hi

I am trying to compile a quite large software system with a new
compiler. During that attempt I am facing problems during the link
phase, and I have traced it down to the following construct:

test.cc:
class Foo
{
public:
virtual ~Foo();
};

class Bar : public Foo
{
public:
virtual ~Bar() {};
};

If I compile this unit all of the previous compilers I have tried will
generate _no_ symbols, since I don't actually use anything here. The
new compiler I have tried gives me:

Undefined symbols from test.o:
typeid<Foo>
Foo::~Foo()
Class tables [Vtable] dependent on key function:
"__versioned_type_info::~__versioned_type_info ()"

So the question is as simple as: Is this a "bug" in the new compiler I
have used, or is it "allowed" to do this according to the
specification...

(In my "real" program the classes reside in separate header files
included by a lot of different "modules" in my system...)

Trond

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am trying to compile a quite large software system with a new
> compiler. During that attempt I am facing problems during the link
> phase, and I have traced it down to the following construct:
>
> test.cc:
> class Foo
> {
> public:
> virtual ~Foo();


A virtual function will be defined or declared pure or both. You
cannot declare a function virtual without providing its definition
somewhere. Period.

> };
>
> class Bar : public Foo
> {
> public:
> virtual ~Bar() {};
> };
>
> If I compile this unit all of the previous compilers I have tried will
> generate _no_ symbols, since I don't actually use anything here. The
> new compiler I have tried gives me:
>
> Undefined symbols from test.o:
> typeid<Foo>
> Foo::~Foo()
> Class tables [Vtable] dependent on key function:
> "__versioned_type_info::~__versioned_type_info ()"
>
> So the question is as simple as: Is this a "bug" in the new compiler I
> have used, or is it "allowed" to do this according to the
> specification...


It is not allowed to have a virtual function that is not pure without
a definition. You can only omit the definition of a virtual function
iff you declare it pure.

> (In my "real" program the classes reside in separate header files
> included by a lot of different "modules" in my system...)


That doesn't matter.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
trond.norbye@gmail.com
Guest
Posts: n/a
 
      09-29-2006

Victor Bazarov wrote:

> > So the question is as simple as: Is this a "bug" in the new compiler I
> > have used, or is it "allowed" to do this according to the
> > specification...

>
> It is not allowed to have a virtual function that is not pure without
> a definition. You can only omit the definition of a virtual function
> iff you declare it pure.
>
> > (In my "real" program the classes reside in separate header files
> > included by a lot of different "modules" in my system...)

>
> That doesn't matter.


This was _exactly_ the kind of information I was looking for

regards,

Trond

 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      09-29-2006
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:
>I am trying to compile a quite large software system with a new
>compiler. During that attempt I am facing problems during the link
>phase, and I have traced it down to the following construct:
>
>test.cc:
>class Foo
>{
> public:
> virtual ~Foo();
>};
>
>class Bar : public Foo
>{
> public:
> virtual ~Bar() {};
>};
>
>If I compile this unit all of the previous compilers I have tried will
>generate _no_ symbols, since I don't actually use anything here. The
>new compiler I have tried gives me:
>
>Undefined symbols from test.o:
> typeid<Foo>
> Foo::~Foo()
> Class tables [Vtable] dependent on key function:
>"__versioned_type_info::~__versioned_type_info( )"
>
>So the question is as simple as: Is this a "bug" in the new compiler I
>have used, or is it "allowed" to do this according to the
>specification...
>
>(In my "real" program the classes reside in separate header files
>included by a lot of different "modules" in my system...)


I don't have my standard in front of me, but I'm fairly
certain that it says that the virtuals need to be defined
but that a diagnostic is not required.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
undefined reference to symbol '_end' Eric C Programming 5 09-02-2012 10:52 PM
Why ":symbol" failed but 'symbol' successed with JRuby 1.0.3? Song Ma Ruby 2 07-20-2008 04:08 AM
undefined reference to `vtable for Segment' due to virtual destructor??? druberego@gmail.com C++ 5 11-20-2006 06:22 PM
Compiler/Linker Error undefined reference to 'std::ios_base::Init::Init[in-charge]() clusardi2k@aol.com C++ 1 08-18-2005 07:11 PM
what's differnece between #ifdef symbol and #if defined(symbol) baumann@pan C Programming 1 04-15-2005 08:25 AM



Advertisments