CReating a DLL whcih can export 'n' number of functions for a client application

  • Helo All,

    I would like to develop a .dll with Qt which can be able to export some 'c' functions to client application. Can experts guide me on this ?

    many thanks,

  • you have to sorround the functions with

    extern "C"
    // do your functions and export definitions here

    if you use MSVS tool chain. Don't know whether it is also needed for others like gcc etc.

  • The easiest way to set up a project for a shared library / DLL is to use the Qt Creator New Project... wizard (and select Other Project / C++ Library). That will give you a good starting point with import / export defines etc.

    If you want to make it a pure C DLL, the interface obviously has to be pure C, no C++ classes as return values or parameters.

  • Er.. this ("__declspec(dllexport)" and "__declspec(dllimport)") is required too.. isn't it?

    #ifdef INMYLIB
    #define MYLIBDEF __declspec(dllexport)
    #define MYLIBDEF __declspec(dllimport)

    #include "MyDllDef.h"

    MYLIBDEF void exported_fn();

    #include <MyLib.h>

    void runFn()

    You might also need to use the extern C.. Look at this "Stack Overflow": post on it.

  • Yeah, that's exactly what you get from the Other Project / C++ Library wizard. That's what I meant by 'import / export defines etc.' (though I agree I could have been a bit more explicit).

  • @ludde: Sorry about that, I hadn't used the feature myself, coding in VS at work.. but you're right the wizard does make it a lot simpler. Cheers :)

    [Edit: @gerolf: Thanks for the info.. i noticed the macros in the wizard generated code.. ]

  • But that's only needed on windows for MSVC compiler, mingw does it in another way, so I suggest using Q_DECL_EXPORT / Q_DECL_IMPORT. They map to the correct, compiler specific code.

Log in to reply

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