Results 1 to 4 of 4

Thread: how to use shared library

  1. #1
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default how to use shared library

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to use shared library

    Just link with the library in your project.

    qmake Code:
    1. LIBS += -lmylibrary
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use shared library

    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

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to use shared library

    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":
    Qt Code:
    1. #include <someclass.h>
    2.  
    3. // . . . some code . . .
    4. SomeClass sc;
    5. // . . .
    To copy to clipboard, switch view to plain text mode 
    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):
    Qt Code:
    1. LIBS += -lmylib #notice no .lib, no .a, no .dll, only the essential name of library
    To copy to clipboard, switch view to plain text mode 
    but if your library is not in path you have to first point the directory:
    Qt Code:
    1. LIBS += -Lpath/to/your/library
    To copy to clipboard, switch view to plain text mode 
    Last edited by faldzip; 25th September 2009 at 22:05.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Event loop in Qt-based shared library
    By sarabito in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2009, 16:45
  2. qmake: dependency of application on common shared library
    By PeterWurmsdobler in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 16:13
  3. Qt/Mac Shared Library
    By nareshqt in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2008, 07:21
  4. Compiled resources in shared library
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2007, 04:57
  5. shared library problem
    By nhatkhang in forum KDE Forum
    Replies: 9
    Last Post: 28th November 2006, 04:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.