PDA

View Full Version : Multiple reasons for vtable and linkage issues



pitonyak
14th February 2010, 21:44
I spent much time today solving vtable issues, and similar linkage issues. I thought that I would share my findings.

I have a class derived from QObject. I added the Q_OBJECT macro, and suddenly I had vtable issues with the class. All you QT veterans are smiling and nodding, because you know that I needed to run qmake to regenerate the make the file.


Check link statements
Verify that the method does indeed exist.
Run qmake to regenerate the MAKEFILE
Only use the Q_OBJECT macro in a header file.



My next issue was subtle. My opinion is that this is probably a compiler error, but, I have not pursued it. This is a bit convoluted:

My program uses library A
Library A uses Library B
While linking, some classes defined in Library B and used in Library A are not available (link issues).


I have not pursued this entirely, but, I solved the problem by instantiating a class instance in my program. Defining an instance in library B did not help.

I was very surprised by this.

high_flyer
15th February 2010, 09:44
While linking, some classes defined in Library B and used in Library A are not available (link issues).
You have to link against both libs from your application, unless lib B is statically linked to A.

pitonyak
15th February 2010, 13:42
I do link to both libraries. The interesting problem is that if I do not instantiate an instance of a class in my main program, but only in library A, then certain things in B are not found. If I did not link both libraries, then creating an instance in the main program would not resolve the link error.