What am I missing? Unresolved externals
Hi,
In porting to Qt4 I'm finally linking but run into unresolved externals:
Code:
link /LIBPATH:"C:\Qt\4.0.1\lib" /NOLOGO /DEBUG /DEBUG /DLL /LIBPATH:../xpaf /LIBPATH:../xpaf xpaf-sdk.lib /LIBPATH:..
/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
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"
@C:\temp\nmCE6.tmp
Creating library debug\xpaf-sdkgui.lib and object debug\xpaf-sdkgui.exp
moc_ezSessionApp.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ezCrm::ezBase::stat
icMetaObject" (?staticMetaObject@ezBase@ezCrm@@2UQMetaObject@@B)
...
...
ezModelGui.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const layerModel::ezBCModel_RTa
ble_Control::staticMetaObject" (?staticMetaObject@ezBCModel_RTable_Control@layerModel@@2UQMetaObject@@B)
debug\xpaf-sdkgui.dll : fatal error LNK1120: 59 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\Bin\nmake.exe"' : return code '0x2'
Stop.
I have
Code:
// Win 32 DLL export macros
#ifdef WIN32
# ifdef BUILD_DLL
# define XPAF_DLL_EXPORT __declspec(dllexport)
# else
# define XPAF_DLL_EXPORT // Empty
# endif
#endif // WIN32
and
Code:
namespace layerModel {
class XPAF_DLL_EXPORT ezBCModel_RItem: public ezBCModelBase
{
Q_OBJECT
public:
ezBCModel_RItem
(ezModelRender
*aParent,
QString aName
=0);
~ezBCModel_RItem(void);
};
...
namespace layerModel {
..
class XPAF_DLL_EXPORT ezBCModel_RTable: public ezBCModel_RItem
{
Q_OBJECT
public:
ezBCModel_RTable
(ezModelRender
*aParent,
QString aName
=0);
~ezBCModel_RTable(void);
};
What am I missing? Namepace messing the name mangling :confused:
DLL_EXPORT :confused:
Any pointers appreciated!!
Re: What am I missing? Unresolved externals
Does appropriate moc_*.cpp file contains the definition of layerModel::ezBCModel_RTable_Control::staticMetaOb ject?
Re: What am I missing? Unresolved externals
In moc_ezBCModel_RTable.cpp:
Code:
const QMetaObject layerModel
::ezBCModel_RTable_Control::staticMetaObject = { { &ezBCModel_RItem_Control::staticMetaObject, qt_meta_stringdata_layerModel__ezBCModel_RTable_Control,
qt_meta_data_layerModel__ezBCModel_RTable_Control, 0 }
};
Re: What am I missing? Unresolved externals
Do you link your application with moc_ezBCModel_RTable.obj?
Re: What am I missing? Unresolved externals
Yup.. it gets linked into the DLL:
Code:
Creating temporary file "C:\temp\RSP00007A.rsp" with contents
[
/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
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBBase.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCAucLot.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCBase.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCContact.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_BC.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_DTable.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_Entity.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RItem.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RScreen.obj"
"\Derick\projects\xpaf\tmp\xpaf-sdk\ezBCModel_RTable.obj"
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.... :confused:
Re: What am I missing? Unresolved externals
Does that class of yours inherit QObject?
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?
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?
Re: What am I missing? Unresolved externals
Re: What am I missing? Unresolved externals
Maybe a more specific hint :) .. I only found some specific macros for plugins.
Re: What am I missing? Unresolved externals
I even tried:
Code:
#include <QtCore/qglobal.h>
// Win 32 DLL export macros
#ifdef WIN32
# ifdef BUILD_DLL
//# define XPAF_DLL_EXPORT __declspec(dllexport)
# define XPAF_DLL_EXPORT Q_DECL_EXPORT
# else
# define XPAF_DLL_EXPORT // Empty
# endif
#endif // WIN32
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?
Re: What am I missing? Unresolved externals
Hmmm... after using:
Code:
#include <QtCore/qglobal.h>
# define XPAF_DLL_EXPORT Q_DECL_EXPORT
And the rebuild of the whole planet... one DLL worked .... :D phew....
Now to sort out the other...
It still is the same unresolved symbols so I'll check some defines...
Re: What am I missing? Unresolved externals
Sigh ... still no joy...
When creating a 2nd DLL the imports of the 1st does not work:
Code:
ezGScreenInterface.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ezCrm::ezBase::staticMetaObject" (?staticMetaObject@ezBase@ezCrm@@2UQMetaObject@@B)
ezGScreenInterfac declated in 2nd DLL
ezBase declared in 1st DLL
Any idea why teh meta object does not get exported in the 1st DLL?
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).
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?
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:
Code:
#ifdef Q_OS_WIN32
# ifdef BUILD_DLL
# define EXPORT __declspec(dllexport)
# else
# define EXPORT __declspec(dllimport)
# endif
#else
# define EXPORT
#endif
together with:
Code:
CONFIG(dll) {
DEFINES += BUILD_DLL
}
in the .pro file should work.
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
Re: What am I missing? Unresolved externals
Quote:
Originally Posted by wysota
There probably is some Qt macro to abstract this a little.
Where? ;)