[Qt-interest] doubt regarding creation of shared libs in QT
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri May 7 14:50:34 CEST 2010
Mandeep Sandhu wrote on Friday, May 07, 2010 11:10 AM:
> ...
> Now taking the same example as shown in this doc, would a client need
> to add the following in its source?
>
> MYSHAREDLIB_EXPORT void foo();
>
> In client source this would translate to: Q_DECL_IMPORT void foo();
>
> Is this correct?
No. The client code is never modified! The only thing you set in your "client project" (the application) is a DEFINE, so when the LIBRARY header is #included the macro is expanded either to Q_DECL_IMPORT or Q_DECL_EXPORT. Read here about the proper technique to export/import symbols from a shared library: http://msdn.microsoft.com/en-us/library/8fskxacy%28VS.80%29.aspx
Where it talks about __declspec(dllexport) you would use Q_DECL_EXPORT instead and in analogy to __declspec(dllimport). In fact, the Qt macro works multiplatform in that it is rendered to "nothing" on all other platforms (Mac OS X, Linux/Unix - but in theory on other platforms it could still render to other compiler-specific "code") - __declspec(dllimport) is a MS compiler specific thing and would not compile on gcc, for example. Hence the preferred use of Q_DECL_IMPORT which takes care of that.
Also search the Qt interest archive, this question comes up every then and when and working examples have been provided. Also study the Qt "Plug'n'Paint" example which makes use of plugins, but the principle of exporting symbols from a plugin and importing them into the actual application is the same.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list