PDA

View Full Version : error definition of static member '...' of dllimport class



hvengel
19th February 2008, 01:00
I have ported my app to Qt4 and I am in the process of testing my build on Windows (I primarily work on Linux) and I am receiving errors that look like this:


build\win32\libqtlcmswidgets\moc_lprofgauge.cc:81: error: definition of static data member 'LProfGauge::staticMetaObject' of dllimport'd class

As you can see it is complaining about something in a moc file being declared as - well I am not sure what this means. The object is question is a custom widget that is in a static library (not in a DLL) and it appears that moc is generating incorrect code that the compiler is chocking on.

This same static library contains other custom widgets (6 in total) and all of the hand written code for the custom widgets it compiling without any error messages. But the build fails when it tries to build the first moc generated code.

I am using MinGW. I have found a few other threads that that touch on this type of error message but in every case it was someone asking how to get a specific application or library to build and being told by the author of that app or library to set something that was very specific to that app or library. So that info was not very helpful for me to understand what this is about and how to fix it. So could someone here point me to a source that explains in general what is causing this error and perhaps how to fix it?

jacek
19th February 2008, 01:06
Do you have anything between class and LProfGauge in LProfGauge's header file?

hvengel
19th February 2008, 01:33
Since it is a custom widget it is defined as:


class QDESIGNER_WIDGET_EXPORT LProfGauge : public QWidget

To test this I changed it to:


class LProfGauge : public QWidget

and it got passed that error. It looks like the compile now works and I am having issues with the linker not finding the Qt libraries which should not be too hard to sort out.

But I would still like to understand what is going on with this. Do I need to define something for the Windows build so that QDESIGNER_WIDGET_EXPORT does not cause a problem on Windows? All of my other widgets predated Qt4 and were ported to Qt4 and these do not have QDESIGNER_WIDGET_EXPORT. But this particular widget was derived from another source and it had QDESIGNER_WIDGET_EXPORT in the declaration for the widget and I left it in since it seemed to work and did not cause any issues on Linux.

jacek
19th February 2008, 13:10
Do I need to define something for the Windows build so that QDESIGNER_WIDGET_EXPORT does not cause a problem on Windows?
This macro is required only for windows' DLLs. It should be empty for static libraries and other systems.

So you need something like this:
#ifdef STATIC_BUILD
# define MY_WIDGET_EXPORT
#else
# define MY_WIDGET_EXPORT QDESIGNER_WIDGET_EXPORT
#endif

(of course you will have to define STATIC_BUILD somehow).

It's because QDESIGNER_WIDGET_EXPORT is meant for designer plugins and you don't link them statically.