Linking a dynamic library in qt creator



  • Hi,

    I'm working for first time with a 3rd party library(qxmpp). I'm on Window and I want to dynamically link the library during run time as the library is under LGPL and I've read it is recommended to use such libraries as dlls.

    This is what I've tried.

    1. Download the source code of library and built the .dll and .lib files.
    2. I've copied the header files into my project include folder and added them in .pro file under HEADERS variable.
    3. I've included the required header from library in .cpp file when I want to use a particular function from the library.
    4. I added the line LIBS+= -LC:/DLL -lqxmpp_d0 and placed the qxmpp_d0.dll and qxmpp_d0.lib in my C:/ drive.
    5. Tried to build my project and but I'm getting many warnings saying "inconsistent dll linkage" and
      errors saying "definition of dll import static date member is not allowd"
      6, I've googled the errors and find that error means I've tried to define a fucntion that is declared as will be picked from a external library. But I haven't done that. The code where the error comes up seems to be generated by MOC.

    I'm guessing I'm missing something obvious here. Can someone help me with this please.


  • Moderators

    1. I've copied the header files into my project include folder and added them in .pro file under HEADERS variable

    That's not how you usually use external libraries. Instead of adding the headers into HEADERS (which adds them to your project) specify the path to where they are located in INCLUDEPATH.

    1. I added the line LIBS+= -LC:/DLL -lqxmpp_d0 and placed the qxmpp_d0.dll and qxmpp_d0.lib in my C:/ drive

    Maybe that's a typo but to be sure: you're adding -LC:/DLL as the directory so you should place the lib in C:/DLL, not C:/.

    Next questions:
    Have you run qmake after modifying your .pro file?
    Are you using the same compiler and the same Qt version to build the lib and your app?



  • Thanks Chris.
    Following your steps worked.


Log in to reply
 

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