[Omnetpp-l] vtable and undefined reference errors after including Define_Module();

863 views
Skip to first unread message

Stefan Fisches

unread,
Feb 11, 2009, 11:53:23 PM2/11/09
to omne...@omnetpp.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello everybody.

I am trying to implement a new protocol in the INET (or rather
INETMANET) packet, which is called LTP.
In my workspace I have LTP.h, LTP.cc, LTP.msg and a few other files...
Compiling works fine up to the point where I include the line
Define_Module( LTP );
into LTP:cc, so that I can use it as a simple module in Omnetpp.

In LTP.h I have the lines

class LTP: public cSimpleModule{
[..]
public:
LTP(){}
virtual ~LTP();
}

and define the LTP destructor later on in LTP.cc.

The lines alone work fine, but together with the Define_Module macro I
get the following errors however:

../out/gcc-debug/src/LTP.o: In function `~LTP':
/home/sfisches/programs/omnetpp-4.0rc1/inet_test/LTP/src/LTP.cc:19:
undefined reference to `vtable for LTP'
/home/sfisches/programs/omnetpp-4.0rc1/inet_test/LTP/src/LTP.cc:19:
undefined reference to `vtable for LTP'
/home/sfisches/programs/omnetpp-4.0rc1/inet_test/LTP/src/LTP.cc:19:
undefined reference to `vtable for LTP'
../out/gcc-debug/src/LTP.o: In function `(anonymous
namespace)::__onstartup_func_16()':
/home/sfisches/programs/omnetpp-4.0rc1/inet_test/LTP/src/LTP.cc:16:
undefined reference to `typeinfo for LTP'
../out/gcc-debug/src/LTP.o: In function `LTP':
/home/sfisches/programs/omnetpp-4.0rc1/inet_test/LTP/src/LTP.h:69:
undefined reference to `vtable for LTP'
collect2: ld returned 1 exit status
make: *** [../out/gcc-debug/src/LTP] Error 1

whereas line 16 is the Define_Module( LTP);
line 19 the ~LTP() destructor
line 69 the constructor stub LTP(){} in the LTP header file.

I noted that Luca Fabbrini already posted 16 Jan 2009 with the same
problem on this list
(http://www.omnetpp.org/listarchive/msg11934.php)

Does anybody have a clue what the problem is?
Did I set up my environment wrong?
Did I miss something in the code?

Thanks,

Stefan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkmTqyIACgkQUmw6+gqP64KWZQCgikGaejLb86ypsJ0JdXEcnO5J
m2cAoLmWchFuoMTf5HnM88Zv8dfnVtBp
=ad0E
-----END PGP SIGNATURE-----
_______________________________________________
Omnetpp-l mailing list
Omne...@omnetpp.org
http://lists.omnetpp.org/mailman/listinfo/omnetpp-l

Alfonso Ariza

unread,
Feb 12, 2009, 4:30:37 AM2/12/09
to omne...@omnetpp.org

> virtual ~LTP();

Sorry, Can the destructor be virtual?


--------------------------------------------------
From: "Stefan Fisches" <ste...@fisches.de>
Sent: Thursday, February 12, 2009 5:53 AM
To: <omne...@omnetpp.org>
Subject: [Omnetpp-l] vtable and undefined reference errors after
includingDefine_Module();

Michele Caramello (mcaramel)

unread,
Feb 12, 2009, 12:36:15 PM2/12/09
to omne...@omnetpp.org, omne...@omnetpp.org
Yes it can.

But the error 'undefined reference to vtable' or so is generated
because the compiler didn't find a definition for the first virtual
method (that goes in the vtable), I.e. the destructor. Provide it with
one and you'll get rid of it

Regards,
Michele

On Feb 12, 2009, at 3:40 AM, "Alfonso Ariza" <aari...@hotmail.com>
wrote:

Stefan Fisches

unread,
Feb 12, 2009, 7:36:01 PM2/12/09
to omne...@omnetpp.org
awesome, that worked :-)

Thanks for that gentleman.
I promise to read up more C++ stuff so I don't have to bug you with
that kind of C++ based problems again.

Cheers,

Stefan

Alfonso Ariza

unread,
Feb 12, 2009, 11:59:06 AM2/12/09
to omne...@omnetpp.org
You can find information about this problem in this address

http://www.daniweb.com/forums/thread114299.html

--------------------------------------------------
From: "Stefan Fisches" <ste...@fisches.de>
Sent: Thursday, February 12, 2009 5:53 AM
To: <omne...@omnetpp.org>
Subject: [Omnetpp-l] vtable and undefined reference errors after
includingDefine_Module();

> -----BEGIN PGP SIGNED MESSAGE-----

Si Chen

unread,
Feb 24, 2012, 3:18:48 PM2/24/12
to omn...@googlegroups.com, omne...@omnetpp.org
But haven't you already "define the LTP destructor later on in LTP.cc."? why can't the compiler find the " a definition for the first virtual method (that goes in the vtable), I.e. the destructor."?
Reply all
Reply to author
Forward
0 new messages