Results 1 to 11 of 11

Thread: DLL Linking Error with a Plugin

  1. #1
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default DLL Linking Error with a Plugin

    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

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Linking Error with a Plugin

    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?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: DLL Linking Error with a Plugin

    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..?
    Last edited by tescrin; 2nd August 2012 at 00:02.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Linking Error with a Plugin

    What happens if you find the moc file for the plugin and add the dllexport modifier?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: DLL Linking Error with a Plugin

    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 )

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Linking Error with a Plugin

    maybe you can zip up your project/some example and post it here. Otherwise it's pretty hard for anyone else to diagnose.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: DLL Linking Error with a Plugin

    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.)
    Attached Files Attached Files
    Last edited by tescrin; 2nd August 2012 at 17:21.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Linking Error with a Plugin

    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:
    Qt Code:
    1. #define QT_STATICPLUGIN
    2.  
    3. #include <QtPlugin>
    4.  
    5. #include <QtGui/QApplication>
    6.  
    7. #include <QPluginLoader>
    8. #include <QMessageBox>
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication a(argc, argv);
    13.  
    14. QPluginLoader loader("D:\\Code_Libraries\\Qt\\4.6.0-rebuild\\plugins\\designer\\BERTSpinbox.dll");
    15.  
    16. QString msg;
    17.  
    18. QObject *plugin = loader.instance();
    19. if (plugin) {
    20. msg="yes";
    21. }
    22. else {
    23. msg="no";
    24. }
    25. QMessageBox::information(NULL, "", msg);
    26.  
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

    I think you using the plugin in the mainwindow ui means you have to figure out how to link it slightly differently.
    Last edited by amleto; 2nd August 2012 at 18:28.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: DLL Linking Error with a Plugin

    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/4616...esigner-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?
    Last edited by tescrin; 2nd August 2012 at 19:54.

  10. #10
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Linking Error with a Plugin

    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
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. The following user says thank you to amleto for this useful post:

    tescrin (2nd August 2012)

  12. #11
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: DLL Linking Error with a Plugin

    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.

Similar Threads

  1. Replies: 1
    Last Post: 2nd December 2011, 08:36
  2. Linking Error
    By amitpatel22 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 28th June 2011, 12:40
  3. Replies: 4
    Last Post: 22nd May 2011, 13:36
  4. Static linking problem with gif plugin, qt 4.6.2, vs 2008
    By colin207 in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2010, 14:39
  5. Qt Creator Just one linking error
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2009, 13:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.