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

Discussion in 'C++' started by trond.norbye@gmail.com, Sep 29, 2006.

  1. Guest

    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
     
    , Sep 29, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Sep 29, 2006
    #2
    1. Advertising

  3. Guest

    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
     
    , Sep 29, 2006
    #3
  4. Greg Comeau Guest

    In article <>,
    <> 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?
     
    Greg Comeau, Sep 29, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    683
    Jules
    Aug 18, 2005
  2. kdotk
    Replies:
    1
    Views:
    312
    Alf P. Steinbach
    Jun 16, 2006
  3. Replies:
    5
    Views:
    721
    Ron Natalie
    Nov 20, 2006
  4. John Goche
    Replies:
    10
    Views:
    784
    Marcus Kwok
    Dec 8, 2006
  5. Eric

    undefined reference to symbol '_end'

    Eric, Sep 2, 2012, in forum: C Programming
    Replies:
    5
    Views:
    637
    Vincenzo Mercuri
    Sep 2, 2012
Loading...

Share This Page