Import Header Files in the .pro file
-
I've been bitten a couple of times now by a pretty subtle mistake that fortunately is quite easy to avoid. The issue occurs when you have a QT custom Widget of some sort that you want to share among different applications, and when you put the Custom Widget code in its own library. The mistake is to add the header for the Widget library to the HEADER list in the application. Doing this (for Windows applications) will cause the compilation of the application to fail with error C2491: '<WidgetLibraryName>::staticMetaObject' : definition of dllimport static data member not allowed. Instead, I've learned the correct thing to do is just make sure INCLUDEPATH has the correct paths so that the Widget Library's external header file(s) can be located. Now all that is fine, but it sure is handy to be able to see a list of those import library headers as part of my project, so my question is: bolded text Is there any QMAKE variable one can use to list import library header files upon which an application (or library) is dependent?
-
Hi @Michael-R-LegakoL-3com-com,
I think a better approach, is to use a macro to apply the dllimport/export, and then enable that macro in the library only.
For example, if you look at qmake's simple_dll test example, the simple.h header contains:
#ifdef SIMPLEDLL_MAKEDLL # define SIMPLEDLL_EXPORT Q_DECL_EXPORT #else # define SIMPLEDLL_EXPORT Q_DECL_IMPORT #endif class SIMPLEDLL_EXPORT Simple { ... }
Then the simple_dll.pro file contains:
DEFINES += SIMPLEDLL_MAKEDLL
So, this way, when the library is being built (via
simple_dll.pro
), then class is dllexport'ed. But when other code uses that same header (in doesn't defineSIMPLEDLL_MAKEDLL
) then that same class is dllimport'ed instead.Typically, you end up doing this sort of thing to many classes in a single library, so rather than having the
#ifdef ... #define ... etc
in each header file, it often ends up being written once in a "global" project header of some kind. For example, Q_CORE_EXPORT gets defined in qglobal.h, then used throughout all of the exported core Qt class headers.Also see:
Cheers.