PDA

View Full Version : DLL Linking Error with a Plugin



tescrin
1st August 2012, 22:35
Alright, bear with me; here's the compiler output: (I added newlines to make it easier to read)

1>Link:
1> Creating library C:\Users\eulmer\Desktop\Qt Replication\testBB\Win32\Release\testBB.lib and object C:\Users\eulmer\Desktop\Qt Replication\testBB\Win32\Release\testBB.exp

1>moc_testbb.obj : error LNK2019: unresolved external symbol
"public: static struct QMetaObject const BERTSpinbox::staticMetaObject" (?staticMetaObject@BERTSpinbox@@2UQMetaObject@@B)
referenced in function
"public: static class QString __cdecl BERTSpinbox::tr(char const *,char const *)" (?tr@BERTSpinbox@@SA?AVQString@@PBD0@Z)

1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const BERTSpinbox::staticMetaObject" (?staticMetaObject@BERTSpinbox@@2UQMetaObject@@B)

1>testbb.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const BERTSpinbox::staticMetaObject" (?staticMetaObject@BERTSpinbox@@2UQMetaObject@@B)

1>C:\Users\eulmer\Desktop\Qt Replication\testBB\Win32\Release\\testBB.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.

here's the undecorated names from the dll (that are relevant)(in order)(using dependency walker):


struct QMetaObject const BERTSpinbox::staticMetaObject
class QString BERTSpinbox::tr(char const *,char const *)


I know I never defined these; but why would I have to?* What am I missing here? What is this darn thing trying to tell me to add? Other plugins (referring to the other thread) worked just fine using the same algorithm for building them (so to speak.)

Researching lead me to believe this has something to do with wchars but I checked the relevant settings in the project file (that i never messed with in the first place mind you) and they are all good. Any thoughts?


*I say that because the only function I called from the DLL was the standard constructor with a QWidget parameter

amleto
1st August 2012, 23:07
Have you put Q_OBJECT in the class def?

Have you correctly linked with the plugin?

Have you correctly exported the class into the dll?

tescrin
1st August 2012, 23:15
Yes
Yes (another plugin using the same folders and such works just fine with no issues.)
Yes (as can be seen by using the dependency walker on it and examining the functions it contains) (also, I corrected it as per the other thread)

EDIT:
After some digging it turns out (I never realized) that declaring Q_OBJECT happens to include a boatload of functions; this function that has no definition is one of those functions. Is this just a random bug that I'll have to work around? Maybe building a new class with the same functionality would work..?

amleto
2nd August 2012, 09:39
What happens if you find the moc file for the plugin and add the dllexport modifier?

tescrin
2nd August 2012, 16:35
Same error :(. I will say that in surveying the moc file I didn't see a function by said name, though it is defined *somewhere* (as I attempted to implement it as a way to test the problem.)

This will sound dumb, but I think I'm going to redo that project really quick and see if it's just some odd project setting I did or... something. I'm out of ideas. If it works I'll just assume I messed with an option I wasn't supposed to (or blame qt :P )

amleto
2nd August 2012, 16:47
maybe you can zip up your project/some example and post it here. Otherwise it's pretty hard for anyone else to diagnose.

tescrin
2nd August 2012, 17:13
I've gone ahead and built an example. It should have all the path/library locations/dependencies set up for you (at least if we had the same macros.)

It does show the same errors (though I didn't check if the mangled names were identical; I assume they are since it's the same code :s.) Thanks for any help!


EDIT: Yeah, it's the code. Just attempted to reuse the code in a fresh qt-designer-plugin project and it's doing the same thing (which.. is to be expected; but still a bit sad.)

amleto
2nd August 2012, 18:28
hmmm.


not sure atm.


I think the problem may be that you are trying to use it before it has been loaded - you need to statically import it, probably using some more qt macros.

Added after 22 minutes:

for example, I got this main to work:


#define QT_STATICPLUGIN

#include <QtPlugin>

#include <QtGui/QApplication>

#include <QPluginLoader>
#include <QMessageBox>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QPluginLoader loader("D:\\Code_Libraries\\Qt\\4.6.0-rebuild\\plugins\\designer\\BERTSpinbox.dll");

QString msg;

QObject *plugin = loader.instance();
if (plugin) {
msg="yes";
}
else {
msg="no";
}
QMessageBox::information(NULL, "", msg);

return a.exec();
}


I think you using the plugin in the mainwindow ui means you have to figure out how to link it slightly differently.

tescrin
2nd August 2012, 19:43
Did you happen to perform any other changes? I've made a similar main.cpp out of yours and still have the linker errors. I'm still not sure why this would be any different than my other plugins. (I'll mention that one lnk2001 is gone since we've removed creation of the object from the main file at compile time.)

I notice your folder is 4.6.0; I'm on 4.8.1 (or whatever the latest is; the directory is called "4.8.1") That doesn't happen to make a difference does it?

EDIT:
trying out this link
http://www.qtcentre.org/threads/46163-Windows-build-fails-when-linking-against-custom-designer-plugin

EDIT2:
Arg...
I'm looking at the name in VS (that it's trying to call) and the name in the Dependency Walker and I noticed that:
Visual Studio: public: static class QString __cdecl BERTSpinbox::tr(char const *,char const *)
.Dll (according to dependency walker): class QString BERTSpinbox::tr(char const *,char const *)

What if... for some reason the __cdecl isn't working as normal?

amleto
2nd August 2012, 19:49
One change I had to do was build the plugin, then change dllexport to dllimport in th eplugin header when building the app.

Different qt version shouldn't make any difference

tescrin
2nd August 2012, 20:00
oh
my

...god.


Thank you so much.



Not only has this made me understand the whole export/import thing I was confused about, but I found that I was using a deprecated header as the reference but using the library for the code; or something to that effect.

I am so happy. I can't put it into words. Thanks!

EDIT: Er, the header file in my C++ "Additional includes" was an older one; and probably always exporting.