PDA

View Full Version : linking problem



high_flyer
4th August 2006, 23:02
Hi,

I have the following case:
Class MTelemetry is defined in an H file, at the moment its an empty class, implementing the defalut constructor and destructor in the H file it self, so there is no implementation file for it.
I subclass it to class MServCon.
Compiling goes well, but the linker complains:

obj/mservcon.o: In function `MServCon::MServCon(QObject*)':
mservcon.cpp:(.text+0x14): undefined reference to `vtable for MTelemetry'

MServCon includes mtelemetry.h.

I tried adding a forward declaration to MServCon, didn't help.
What I might be missing?
Here is the link line:

g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.1.4/lib -o TMServCon obj/main.o obj/mservcon.o obj/moc_mservcon.o -L/usr/local/Trolltech/Qt-4.1.4/lib -lQtNetwo

Thanks.

Ofcourse one second oafter I posted I realized the problem - MTelemetry didn't get moc'ed...

wysota
7th August 2006, 11:08
So did you solve that problem? You should be able to do that by adding an #include "filename.moc" statement to the header file. Qmake should then force moc to process your file. At least it works when you put that statement into an implementation (.cpp) module where the class header is, but maybe it works this way round too.

high_flyer
7th August 2006, 14:30
Yes I did, thanks.
The problem with adding #include "mocfile" (which I tried at first) is that it has to be included in the makefile ofcourse, but it got to be a problem because I am working with KDevelop, and it automatically generates makefiles, so changing them manually is only good till the next qmake.
I was looking (at first) for a way to have some classes just included as header files, so I wont need to have copies in the subprojects.
I ended up creating a lib with my abstract classes as a subproject (which then gets moc'ed as well) and it solved all my problems.
(I hope this was clear enough)