Results 1 to 11 of 11

Thread: Compiling a dll (TEMPLATE =LIB) with MSVC2012 leads to unresolved external symbol

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Compiling a dll (TEMPLATE =LIB) with MSVC2012 leads to unresolved external symbol

    Your plugin project should have an include file like this:

    Qt Code:
    1. // myplugin_global.h
    2. #ifndef MYPLUGIN_GLOBAL_H
    3. #define MYPLUGIN_GLOBAL_H
    4.  
    5. #include <QtCore/qglobal.h>
    6.  
    7. #ifdef MYPLUGIN_LIB
    8. # define MYPLUGIN_EXPORT Q_DECL_EXPORT
    9. #else
    10. # define MYPLUGIN_EXPORT Q_DECL_IMPORT
    11. #endif
    12.  
    13. #endif // MYPLUGIN_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 

    and each of the classes that you want to export from your plugin DLL should be declared this way:

    Qt Code:
    1. #ifndef MYPLUGIN_H
    2. #define MYPLUGIN_H
    3.  
    4. #include <QObject>
    5. #include <QtPlugin>
    6.  
    7. #include <IMyPlugin.h> // defines pure virtual interfaces implemented by MyPlugin
    8.  
    9. #include "myplugin_global.h"
    10.  
    11. class MYPLUGIN_EXPORT MyPlugin
    12. : public QObject
    13. , public IMyPlugin // the interface supported by your plugin class
    14. {
    15. Q_OBJECT;
    16. Q_PLUGIN_METADATA( IID "com.MyCompany.IMyPlugin" );
    17. Q_INTERFACES( IMyPlugin );
    18.  
    19. // ... constructor, destructor, and implementation of iMyPlugin virtual methods
    20. };
    21.  
    22. #endif // MYPLUGIN_H
    To copy to clipboard, switch view to plain text mode 

    Such classes compile and link into a DLL just fine in MSVC2012 on my system. I did have the experience with undefined externals, but this appears to be a glitch in MSVC. If you do a clean rebuild, I think they go away. It's been a long time, so I don't remember exactly what I did - I remember there was some mis-configuration, but I use vcxproj files, not .pro files.

    You might also check to make sure that "MYPLUGIN_LIB" is defined when compiling your DLL, and not defined when you link your DLL as an ordinary (not dynamically loaded) DLL (by linking to the corresponding .LIB that defines the entry points that will be resolved at runtime)

  2. The following user says thank you to d_stranz for this useful post:

    maitai (3rd December 2013)

Similar Threads

  1. Qt5 and MSVC2012 - unresolved external error
    By Blood9999 in forum Newbie
    Replies: 2
    Last Post: 16th February 2013, 20:26
  2. unresolved external symbol for QGLWidget
    By Wasabi in forum Newbie
    Replies: 1
    Last Post: 13th May 2011, 11:56
  3. unresolved external symbol
    By gridolfi in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2009, 17:58
  4. unresolved external symbol
    By tgreaves in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2009, 19:49
  5. Unresolved External Symbol
    By munna in forum General Discussion
    Replies: 1
    Last Post: 10th May 2006, 19:25

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
  •  
Qt is a trademark of The Qt Company.