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.
- Download the source code of library and built the .dll and .lib files.
- I've copied the header files into my project include folder and added them in .pro file under HEADERS variable.
- I've included the required header from library in .cpp file when I want to use a particular function from the library.
- I added the line LIBS+= -LC:/DLL -lqxmpp_d0 and placed the qxmpp_d0.dll and qxmpp_d0.lib in my C:/ drive.
- 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.
-
- 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.
- 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 inC:/DLL
, notC:/
.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?