Shared Library: Import and export simultaneously ?



  • Hello ,
    I have a solution which contains of several projects

    !http://img705.imageshack.us/img705/1500/sharedn.png(Architecture)!

    as you can see.
    There is the main project which includes the main.exe.
    Then I have a few shared.dll libraries, which have several functionalities.
    Furtheron, I plan to separate common used functions into other shared dll's (util.dll's), see third layer.

    • Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library.
    • Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library.

    Since my shared.dll's should be compiled as a shared library, so I have set the macro Q_DECL_EXPORT
    Furtheron, my shared.dll's are compiled as a client that uses the shared library (util.dll), so I have to set the Q_DECL_IMPORT macro?

    Any suggestions? Are there any suitable possibilities..?

    Cheers Huck

    [EDIT: fixed image link, Volker]



  • In your dll project file define something like this:
    @
    #define YOUR_LIBRARY
    @

    then in dll public header, define something like this:
    @
    #if defined(YOUR_LIBRARY)

    define YOUR_PUBLIC_DEFINE Q_DECL_EXPORT

    #else

    define YOUR_PUBLIC_DEFINE Q_DECL_IMPORT

    #endif
    @

    Then every class, function or varibale that you want to be exported, must pe preceded by YOUR_PUBLIC_DEFINE

    For example:
    @
    YOUR_PUBLIC_DEFINE yourClass{ ... }
    YOUR_PUBLIC_DEFINE void yourFunnction() {...}
    @

    [edit] I wanted to say project preprocessor defines, and not define YOUR_LIBRARY in header file
    So if you use qmake, in project file write
    @
    DEFINES += YOUR_LIBRARY
    @
    In VC, goto in project settings, C++ -> Preprocessor -> Preprocessor definitions




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.