[Qt-interest] Exporting function
Eric Clark
eclark at ara.com
Thu Mar 4 22:20:59 CET 2010
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of André Hänsel
> Sent: Thursday, March 04, 2010 2:34 PM
> To: 'Qt-interest'
> Subject: Re: [Qt-interest] Exporting function
>
> J-P Nurmi wrote:
> > On Thu, Mar 4, 2010 at 10:18 PM, André Hänsel <andre at webkr.de> wrote:
> > > Hi list,
> > >
> > > what is the correct way to export a function using Qt and MSVC?
> > >
> > > With
> > >
> > > extern "C" HRESULT Q_DECL_EXPORT __stdcall
> DllGetClassObject(REFCLSID
> > > objGuid, REFIID factoryGuid, LPVOID *factoryHandle)
> > >
> > > I get an "Redefinition; different linkage" error.
> > >
> > > Regards,
> > > André
> > >
> >
> > Hi,
> >
> > You export when building the lib and import when using the lib.
> >
> > .pro:
> > DEFINES += BUILD_MY_LIB
> >
> > .h
> > #ifdef BUILD_MY_LIB
> > #define MY_EXPORT Q_DECL_EXPORT
> > #else
> > #define MY_EXPORT Q_DECL_IMPORT
> > #endif
This is the actual code behind Q_DECL_EXPORT and Q_DECL_IMPORT:
#ifdef BUILD_MY_LIB
#define MY_EXPORT __declspec(dllexport)
#else
#define MY_EXPORT __declspec(dllimport)
#endif
And, yes, that is 2 (two) underscores in front of declspec! The define, BUILD_MY_LIB, can only be defined in the lib that is exporting the functions. Any lib that tries to use your lib, CANNOT have BUILD_MY_LIB defined.
Hope this helps,
Eric
> >
> > And then use MY_EXPORT instead of Q_DECL_EXPORT/IMPORT directly.
>
> Yes, of course, I have:
>
> #if defined(COM_LIBRARY)
> # define COMSHARED_EXPORT Q_DECL_EXPORT
> #else
> # define COMSHARED_EXPORT Q_DECL_IMPORT
> #endif
>
> But because of the define this is the same:
> extern "C" HRESULT COMSHARED_EXPORT __stdcall
> DllGetClassObject(REFCLSID
> objGuid, REFIID factoryGuid, LPVOID *factoryHandle)
>
> and so gives the same error.
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list