Page 1 of 3 123 LastLast
Results 1 to 20 of 50

Thread: What am I missing? Unresolved externals

  1. #1
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy What am I missing? Unresolved externals

    Hi,

    In porting to Qt4 I'm finally linking but run into unresolved externals:

    Qt Code:
    1. link /LIBPATH:"C:\Qt\4.0.1\lib" /NOLOGO /DEBUG /DEBUG /DLL /LIBPATH:../xpaf /LIBPATH:../xpaf xpaf-sdk.lib /LIBPATH:..
    2. /xpaf-sdk/debug /LIBPATH:../../lua-5.0.2/lib ../../lua-5.0.2/lib\lualib.lib C:\Qt\4.0.1\lib\QtCored4.lib C:\Qt\4.0.1\lib\QtGu
    3. id4.lib C:\Qt\4.0.1\lib\Qt3Supportd4.lib C:\Qt\4.0.1\lib\QtSqld4.lib C:\Qt\4.0.1\lib\QtXmld4.lib /OUT:"debug\xpaf-sdkgui.dll"
    4. @C:\temp\nmCE6.tmp
    5. Creating library debug\xpaf-sdkgui.lib and object debug\xpaf-sdkgui.exp
    6. moc_ezSessionApp.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ezCrm::ezBase::stat
    7. icMetaObject" (?staticMetaObject@ezBase@ezCrm@@2UQMetaObject@@B)
    8. ...
    9. ...
    10. ezModelGui.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const layerModel::ezBCModel_RTa
    11. ble_Control::staticMetaObject" (?staticMetaObject@ezBCModel_RTable_Control@layerModel@@2UQMetaObject@@B)
    12. debug\xpaf-sdkgui.dll : fatal error LNK1120: 59 unresolved externals
    13. NMAKE : fatal error U1077: 'link' : return code '0x460'
    14. Stop.
    15. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\Bin\nmake.exe"' : return code '0x2'
    16. Stop.
    To copy to clipboard, switch view to plain text mode 

    I have
    Qt Code:
    1. // Win 32 DLL export macros
    2. #ifdef WIN32
    3. # ifdef BUILD_DLL
    4. # define XPAF_DLL_EXPORT __declspec(dllexport)
    5. # else
    6. # define XPAF_DLL_EXPORT // Empty
    7. # endif
    8. #endif // WIN32
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. namespace layerModel {
    2.  
    3. class XPAF_DLL_EXPORT ezBCModel_RItem: public ezBCModelBase
    4. {
    5. Q_OBJECT
    6. public:
    7. ezBCModel_RItem(ezModelRender *aParent, QString aName=0);
    8. ~ezBCModel_RItem(void);
    9. };
    10. ...
    11. namespace layerModel {
    12. ..
    13. class XPAF_DLL_EXPORT ezBCModel_RTable: public ezBCModel_RItem
    14. {
    15. Q_OBJECT
    16. public:
    17. ezBCModel_RTable(ezModelRender *aParent, QString aName=0);
    18. ~ezBCModel_RTable(void);
    19. };
    To copy to clipboard, switch view to plain text mode 

    What am I missing? Namepace messing the name mangling
    DLL_EXPORT

    Any pointers appreciated!!
    Derick Schoonbee

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Does appropriate moc_*.cpp file contains the definition of layerModel::ezBCModel_RTable_Control::staticMetaOb ject?

  3. #3
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    In moc_ezBCModel_RTable.cpp:
    Qt Code:
    1. const QMetaObject layerModel::ezBCModel_RTable_Control::staticMetaObject = {
    2. { &ezBCModel_RItem_Control::staticMetaObject, qt_meta_stringdata_layerModel__ezBCModel_RTable_Control,
    3. qt_meta_data_layerModel__ezBCModel_RTable_Control, 0 }
    4. };
    To copy to clipboard, switch view to plain text mode 
    Derick Schoonbee

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Do you link your application with moc_ezBCModel_RTable.obj?

  5. #5
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Yup.. it gets linked into the DLL:

    Qt Code:
    1. Creating temporary file "C:\temp\RSP00007A.rsp" with contents
    2. [
    3. /OUT:"debug\xpaf-sdk.dll" /NOLOGO /LIBPATH:"C:\Derick\projects\xpaf\xpaf-sdk\debug" /LIBPATH:"C:\Qt\4.0.1\lib" /DLL /DEBUG /SUBSYSTEM:WINDOWS /LIBPATH:../xpaf /LIBPATH:../xpaf /LIBPATH:../../lua-5.0.2/lib ../../lua-5.0.2/lib\lualib.lib C:\Qt\4.0.1\lib\QtCored4.lib C:\Qt\4.0.1\lib\QtGuid4.lib C:\Qt\4.0.1\lib\QtSqld4.lib C:\Qt\4.0.1\lib\QtXmld4.lib C:\Qt\4.0.1\lib\Qt3Supportd4.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
    4. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBBase.obj"
    5. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCAucLot.obj"
    6. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCBase.obj"
    7. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCContact.obj"
    8. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_BC.obj"
    9. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_DTable.obj"
    10. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_Entity.obj"
    11. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RItem.obj"
    12. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RScreen.obj"
    13. "\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RTable.obj"
    To copy to clipboard, switch view to plain text mode 
    Derick Schoonbee

  6. #6
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Found something:

    After undefining XPAF_DLL_EXPORT the unresolved externals went away...

    Is there a difference in Qt4? I think I read somewhere that the moc now understands macro expantions....
    Derick Schoonbee

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Does that class of yours inherit QObject?

  8. #8
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Yes they do.

    When I build the DLL my classes are not exported. I even tried to export my classes with:

    # define XPAF_DLL_EXPORT Q_DECL_EXPORT
    and
    # define XPAF_DLL_EXPORT __declspec(dllexport)

    Anything that I should try with QT4?
    Derick Schoonbee

  9. #9
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Does anybody have some sample classes exported in external DLLs? Please

    My code compiles but I get an error as my DLL does not show the exported classes. Or do we need to load DEF files?
    Derick Schoonbee

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Check Qt4 sources

  11. #11
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Maybe a more specific hint .. I only found some specific macros for plugins.
    Derick Schoonbee

  12. #12
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    I even tried:

    Qt Code:
    1. #include <QtCore/qglobal.h>
    2. // Win 32 DLL export macros
    3. #ifdef WIN32
    4. # ifdef BUILD_DLL
    5. //# define XPAF_DLL_EXPORT __declspec(dllexport)
    6. # define XPAF_DLL_EXPORT Q_DECL_EXPORT
    7. # else
    8. # define XPAF_DLL_EXPORT // Empty
    9. # endif
    10. #endif // WIN32
    To copy to clipboard, switch view to plain text mode 
    Derick Schoonbee

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    Are you sure you pinpointed the problem correctly? It looks like your plugin can't resolve a symbol. I know it shouldn't even try to, but... It looks like an overall compiler issue not a Qt one. Try to build any plugin which needs an external dependency (for example one that needs a "foo()" function. When you succeed, you'll come back to Qt. Maybe you lack some compiler option?

  14. #14
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Hmmm... after using:
    Qt Code:
    1. #include <QtCore/qglobal.h>
    2. # define XPAF_DLL_EXPORT Q_DECL_EXPORT
    To copy to clipboard, switch view to plain text mode 

    And the rebuild of the whole planet... one DLL worked .... phew....
    Now to sort out the other...
    It still is the same unresolved symbols so I'll check some defines...
    Derick Schoonbee

  15. #15
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What am I missing? Unresolved externals

    Sigh ... still no joy...

    When creating a 2nd DLL the imports of the 1st does not work:
    Qt Code:
    1. ezGScreenInterface.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ezCrm::ezBase::staticMetaObject" (?staticMetaObject@ezBase@ezCrm@@2UQMetaObject@@B)
    To copy to clipboard, switch view to plain text mode 

    ezGScreenInterfac declated in 2nd DLL
    ezBase declared in 1st DLL

    Any idea why teh meta object does not get exported in the 1st DLL?
    Derick Schoonbee

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by derick
    When creating a 2nd DLL the imports of the 1st does not work:
    When you compile code that will use your DLL (not the DLL itself), you need __declspec(dllimport) (in the same place where __declspec(dllexport) was).

  17. #17
    Join Date
    Feb 2006
    Posts
    32
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    I sorry, I am having a problem very similar to this, but when reading this thread I keep thinking, shouldn't Qt be abstracting all this?

    Where in the Qt documentation does it say I need to have "dllexport", "dllimport" declarations everywhere?

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by Paul Drummond
    Where in the Qt documentation does it say I need to have "dllexport", "dllimport" declarations everywhere?
    Probably nowhere, it's specific only to windows DLLs --- normal systems doesn't require this.

    Moreover what you should put before the class name depends on the way use use your code. If the header is used for compilation of a DLL, it should be dllexport, otherwise it should be dllimport, but how could Qt know this?

    Something like this:
    Qt Code:
    1. #ifdef Q_OS_WIN32
    2. # ifdef BUILD_DLL
    3. # define EXPORT __declspec(dllexport)
    4. # else
    5. # define EXPORT __declspec(dllimport)
    6. # endif
    7. #else
    8. # define EXPORT
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    together with:
    Qt Code:
    1. CONFIG(dll) {
    2. DEFINES += BUILD_DLL
    3. }
    To copy to clipboard, switch view to plain text mode 
    in the .pro file should work.

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What am I missing? Unresolved externals

    There probably is some Qt macro to abstract this a little. The macro should expand to empty code on platforms other than Win32 and to that export macro on Windows

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What am I missing? Unresolved externals

    Quote Originally Posted by wysota
    There probably is some Qt macro to abstract this a little.
    Where?

Similar Threads

  1. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 18:50
  2. shared vs static
    By alisami in forum Installation and Deployment
    Replies: 3
    Last Post: 4th October 2008, 14:04
  3. Replies: 16
    Last Post: 23rd May 2008, 11:12
  4. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 17:06
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 23:04

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.