Results 1 to 4 of 4

Thread: Dynamic library in windows

  1. #1
    Join Date
    Apr 2012
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dynamic library in windows

    Hi
    I want to make dynamic library on windows
    I using qt creator 2.4 and msvc 2010

    In qmake i write this commands
    Qt Code:
    1. QT -= core gui
    2.  
    3. TEMPLATE = lib
    4.  
    5. CONFIG += dll
    To copy to clipboard, switch view to plain text mode 
    Project build without issues but in in build directory i found only .dll file without .lib file
    ( I need from this .lib to link to this .dll )
    What im doing wrong ???

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Dynamic library in windows

    Does your code export any symbols? It's possible that there will be no import library if there are no exported symbols to import. See Creating Shared Libraries. I get an import library when I do a trivial example using the MingW tools (I don't have MSVC handy) but GCC exports by default.

    Does this simple example do what you expect?
    Qt Code:
    1. // Pro file
    2. TEMPLATE = lib
    3. QT -= core gui
    4. CONFIG += dll
    5. DEFINES += MYSHAREDLIB_LIBRARY
    6. SOURCES += mysharedlib.cpp
    7.  
    8. // mysharedlib.h
    9.  
    10. #include <QtCore/QtGlobal>
    11. #if defined(MYSHAREDLIB_LIBRARY)
    12. # define MYSHAREDLIB_EXPORT Q_DECL_EXPORT
    13. #else
    14. # define MYSHAREDLIB_EXPORT Q_DECL_IMPORT
    15. #endif
    16.  
    17. MYSHAREDLIB_EXPORT int doSomethingInsightful();
    18.  
    19. class MYSHAREDLIB_EXPORT ExportedClass {
    20. ExportedClass();
    21. int doSomething();
    22. };
    23.  
    24. // mysharedlib.cpp
    25.  
    26. #include "mysharedlib.h"
    27.  
    28. int doSomethingInsightful()
    29. {
    30. return 42;
    31. }
    32.  
    33. ExportedClass::ExportedClass()
    34. {
    35. }
    36.  
    37. int ExportedClass::doSomething()
    38. {
    39. return 0;
    40. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    themean (1st May 2012)

  4. #3
    Join Date
    Apr 2012
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic library in windows

    Thanks
    Is it possible for some one that not use Qt ,Qt creator or qmake to use
    this library build in that way

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Dynamic library in windows

    Yes, as long as the DLL does not link to any Qt component. The above uses macros defined by Qt headers but you could easily produce a non-Qt version of those macros to provide complete independence.

    With the C++ example the user would have to be using the same compiler/linker type to cope with name mangling: e.g. if you built the DLL with MSVC they would need to use MSVC, if you build with MinGW/GCC they would need to use GCC.

    If the interface is C-style then any compiler/linker should be able to use it.

  6. The following user says thank you to ChrisW67 for this useful post:

    themean (1st May 2012)

Similar Threads

  1. Using content from a dynamic library (Windows)
    By MasterBLB in forum Qt Programming
    Replies: 8
    Last Post: 9th August 2011, 14:32
  2. Dynamic library on Mac, Library not loaded
    By grayfox in forum Newbie
    Replies: 2
    Last Post: 2nd July 2011, 02:42
  3. Dynamic library with GUI for Mac
    By mouse_sonya in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2010, 12:23
  4. Linking Qt in a dynamic library
    By dave_mm0 in forum Qt Programming
    Replies: 4
    Last Post: 18th July 2009, 16:28
  5. How to use a Dynamic Link Library with QT / C++.
    By nivaldonicolau in forum Newbie
    Replies: 5
    Last Post: 29th April 2009, 14:05

Tags for this Thread

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.