PDA

View Full Version : how to use shared library



assismvla
25th September 2009, 16:29
I create a shared library (dll) that extend QTreeWidget with some customizations in the component. ok no problem.

But how can i use my dll (shared library) in others projects ?

wysota
25th September 2009, 17:28
Just link with the library in your project.

LIBS += -lmylibrary

assismvla
25th September 2009, 20:39
I did this:

LIBS += -lMenuS.dll

What is the next step ?

It is ready to use in my project ?
I have to "#include" it on my project too ?

I recived "error: collect2: ld returned 1 exit status" with the line above

faldzip
25th September 2009, 21:29
you link to some library instead of having .cpp files with implementation. So if you want to use some code you have to #include header where that code is declared. Then you have to have the .cpp with definition or library where implementation is already compiled.
So if you have mylib.dll and mylib.lib (or libmylib.a for mingw) where SomeClass has implementation you have to #include the header, lets say "someclass.h":


#include <someclass.h>

// . . . some code . . .
SomeClass sc;
// . . .

and you have to link to the library (exactly in this moment you are linking to the .lib or .a file apropriate to your library) (in .pro file):


LIBS += -lmylib #notice no .lib, no .a, no .dll, only the essential name of library

but if your library is not in path you have to first point the directory:


LIBS += -Lpath/to/your/library