Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. CReating a DLL whcih can export 'n' number of functions for a client application
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KennedyDayala
    wrote on 21 Jun 2011, 12:34 last edited by
    #1

    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,

    Never Ever Give Up

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 21 Jun 2011, 12:41 last edited by
      #2

      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.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludde
        wrote on 21 Jun 2011, 13:48 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jim_kaiser
          wrote on 21 Jun 2011, 17:13 last edited by
          #4

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

          MyDllDef.h
          @
          #ifdef INMYLIB
          #define MYLIBDEF __declspec(dllexport)
          #else
          #define MYLIBDEF __declspec(dllimport)
          #endif
          @

          MyLib.h
          @
          #include "MyDllDef.h"

          MYLIBDEF void exported_fn();
          @

          MyApp.cpp
          @
          #include <MyLib.h>

          void runFn()
          {
          exported_fn();
          }
          @

          You might also need to use the extern C.. Look at this "Stack Overflow":http://stackoverflow.com/questions/2288293/windows-c-extern-declspecdllimport post on it.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            ludde
            wrote on 21 Jun 2011, 18:19 last edited by
            #5

            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).

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jim_kaiser
              wrote on 21 Jun 2011, 18:51 last edited by
              #6

              @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.. ]

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on 21 Jun 2011, 19:01 last edited by
                #7

                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.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0

                1/7

                21 Jun 2011, 12:34

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved