This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

strange linker messages ...


Hi EGCS folks !

When compiling the following erronious code with egcs-1.0.2 you 
get a misleading message from the linker:

// START
int main ()     {}

class LEAF

{       double width () const           { return (0.0); }

public:
        LEAF () {}

        void          calc  () const;
        virtual void  virt2 () const;
//
// Here we have an ERROR
// The declaration should be: virtual void  virt2 () const = 0;
//
};

class NODE: public LEAF

{
public:
        NODE () {}

        virtual void virt2 () const;
};

void LEAF::calc () const

{       double  w = width ();
}

void NODE::virt2 () const

{
}
// END


Compiling the above code with (e)g++ -Wall bug.cc -o bug results in
the following message:

bug.cc: In method `void LEAF::calc() const':
bug.cc:26: warning: unused variable `double w'
/tmp/cca006371.o: In function `LEAF::calc(void) const':
/tmp/cca006371.o(.text+0x18): undefined reference to `LEAF::width(void)
const'
/tmp/cca006371.o: In function `NODE::NODE(void)':
/tmp/cca006371.o(.text+0x41): undefined reference to `LEAF::LEAF(void)'
/tmp/cca006371.o: In function `NODE type_info function':
/tmp/cca006371.o(.text+0x69): undefined reference to `LEAF type_info
function'
/tmp/cca006371.o(.text+0x70): undefined reference to `LEAF type_info
node'
collect2: ld returned 1 exit status

The warning about the `undefined reference to LEAF::width(void) const' 
is incorrect.

When the bogus declaration of virt2 is replaced by a correct one, no
linker messages are shown.

Since (typing) errors like the above can happen quite easily, either a
warning message from the compiler or correct linker messages would be
of big help (Something like: LEAF::virt2 () never defined).


regards,
T.Binder


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]