Results 1 to 16 of 16

Thread: build lib and dll with qmake

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default build lib and dll with qmake

    hi,

    i want to build a dynamic library using qmake. using the template 'lib'
    and CONFIG += dll it builds a dll.
    nevertheless, to link that library to a programm i need the .lib ? how
    can a build a .dll and a .lib at the same time?

    best regards,
    jh

  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: build lib and dll with qmake

    Hmm.. I think it should be created automatically (did you remember about __declspec(dllexport)?), but if it's not the case, read this:
    http://support.microsoft.com/kb/131313

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by wysota View Post
    Hmm.. I think it should be created automatically (did you remember about __declspec(dllexport)?), but if it's not the case, read this:
    http://support.microsoft.com/kb/131313
    the __declspec() stuff is not portable... If you use Qt you should rely on the convinience macros : Q_DECL_EXPORT and Q_DECL_IMPORT instead. The first one has to be set when building a dll and the second one when linking to a dll. They can be managed either by an include file common to all the files of the dll, typically looking like this :
    Qt Code:
    1. #ifdef _X_BUILD_
    2. #if (defined(QT_DLL) || defined(QT_SHARED)) && !defined(QT_PLUGIN)
    3. // lib being compiled shared
    4. #define X_EXPORT Q_DECL_EXPORT
    5. #else
    6. // lib being embedded
    7. #define X_EXPORT
    8. #else
    9. // lib being linked against (must be shared on Window$!)
    10. #define X_EXPORT Q_DECL_IMPORT
    11. #endif
    To copy to clipboard, switch view to plain text mode 
    or inside the projects through the DEFINES variable. In the dll project
    Qt Code:
    1. DEFINES += -DX_EXPORT=Q_DECL_EXPORT
    To copy to clipboard, switch view to plain text mode 
    and in the client project :
    Qt Code:
    1. DEFINES += -DX_EXPORT=Q_DECL_IMPORT
    To copy to clipboard, switch view to plain text mode 

    Then all classes/function/variables meant to be exported (accessible when linking against the lib) have to be prefixed with X_EXPORT (or whatever the name choosen ). For instance :
    Qt Code:
    1. X_EXPORT void someFunction();
    2.  
    3. class X_EXPORT someClass
    4. {
    5. public:
    6. someClass();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Hope this helps.
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    the problem is that if i set
    CONFIG += staticlib it builds a .lib and if i set
    CONFIG += dll it builds a .dll. i want both at the same time.

    best regards,
    jh

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    the problem is that if i set
    CONFIG += staticlib it builds a .lib and if i set
    CONFIG += dll it builds a .dll. i want both at the same time.

    best regards,
    jh
    You're unclear... Do you want both static and shared libraries or a shared one and it's import library (which can only be static...)? In the first case what you need is to add : "CONFIG += static_and_shared" (or it might as well be shared_and_static, I don't remember exactly). But then you might face troubles : the static lib could overwrite (or be overwritten) by the import library of the shared one...
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    actually i want a shared library (dll).

    but if you want to use that library you have to link a *.lib to
    your program at compile time and ship then the *.dll with your exe so
    you can use the shared library at run time.

    for instance, that is the code i used to put in my makefiles i created
    without qmake:

    Qt Code:
    1. libbasic: $(BASIC_OBJ)
    2. link \
    3. /NOLOGO $(QTLIB) opengl32.lib vfw32.lib gdi32.lib user32.lib \
    4. /BASE:0x39D00000 \
    5. /SUBSYSTEM:windows /DLL /incremental:no /VERSION:3.31 \
    6. /out:libbasic.dll /implib:libbasic.lib \
    7. /LIBPATH:"$(QTDIR)\lib" $(BASIC_OBJ)
    8. lib /out:libbasic.lib /subsystem:console $(BASIC_OBJ)
    To copy to clipboard, switch view to plain text mode 

    this builds from obj files a libbasic.lib and a libbasic.dll.


    regards,
    jh

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    actually i want a shared library (dll).

    but if you want to use that library you have to link a *.lib to
    your program at compile time and ship then the *.dll with your exe so
    you can use the shared library at run time.
    qmake has no problem doing this... Do you use the commercial edition of Qt? If so your question doesn't make sense because everything is properly handled by the VS integration. Otherwise it does not make sense either because VS is not supported by the Open Source edition of Qt... In this case you have to fallback to MinGW which does not generate .lib along with .dll but .a instead...

    Is that clear enough???
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    yes, i use the commercial version of qt on windows. but i do not use the
    vs ide. i use xemacs and msys.

    regards,
    jh

  9. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    yes, i use the commercial version of qt on windows. but i do not use the
    vs ide. i use xemacs and msys.
    Commercial Qt but not VS ??? Sounds quite weird but anyway : MSYS uses MinGW AFAIK so you definitely don't need any .lib file! Can build your lib and check for a .a file??? If it is not present you should take care of the macro stuff mentioned earlier in the thread and if it is all you troubles should seem so far away...
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    i bought and installed visual studio C++, but i do not use the IDE
    because i do not like the editor. i use xemacs for editing source code,
    msys as a shell and just the plain c++ compiler (cl, link) to compile
    and link the code. almost the same way i used to compile code when
    i programmed on unix systems. i even wrote makefiles by myself but
    now i also want my qt programs on my MacMini (opensource version of qt,
    gnu c++). so i started playing around with qmake to generate makefiles. but when
    i specify a shared lib i only get the dll without the import library (.lib)
    on windows, which i need to link the library to the exe.

    best regards,
    jh

  11. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    ithe import library (.lib)
    That's where you're wrong... .lib are generated by MSVC *ONLY* the GNU toolchain (whatever the platform) generates a .a instead Is this .a file present after compilation or not???
    Current Qt projects : QCodeEdit, RotiDeCode

  12. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    i know that .a is only for gnu. the problem is not on the Mac.

    the problem is on the windows side (MS VC++) because i do not
    get the .lib, only the .dll ?!

    here is my .pro file:
    Qt Code:
    1. TEMPLATE = lib
    2.  
    3. # CONFIG += dll
    4. # CONFIG += staticlib
    5. CONFIG += static_and_shared
    6.  
    7. DEFINES += _VMP_WINDOWS_
    8. # DEFINES += _DEBUG_basic_hashcode_
    9.  
    10. QMAKE_CLEAN += *~
    11.  
    12. TARGET = basic
    13. DEPENDPATH += .
    14. INCLUDEPATH += .
    15.  
    16. QT += network
    17. VERSION = 1.0.0
    18.  
    19. target.path = ../_libs
    20. INSTALLS += target
    21.  
    22. # Input
    23. HEADERS += basic.h Exception.h MessageService.h
    24. SOURCES += basic.cpp Exception.cpp MessageService.cpp
    To copy to clipboard, switch view to plain text mode 

    i run qmake, i run nmake and get a .dll (but no .lib)

    jh

  13. #13
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    i know that .a is only for gnu. the problem is not on the Mac.

    the problem is on the windows side (MS VC++) because i do not
    get the .lib, only the .dll ?!

    here is my .pro file:
    Qt Code:
    1. TEMPLATE = lib
    2.  
    3. # CONFIG += dll
    4. # CONFIG += staticlib
    5. CONFIG += static_and_shared
    6.  
    7. DEFINES += _VMP_WINDOWS_
    8. # DEFINES += _DEBUG_basic_hashcode_
    9.  
    10. QMAKE_CLEAN += *~
    11.  
    12. TARGET = basic
    13. DEPENDPATH += .
    14. INCLUDEPATH += .
    15.  
    16. QT += network
    17. VERSION = 1.0.0
    18.  
    19. target.path = ../_libs
    20. INSTALLS += target
    21.  
    22. # Input
    23. HEADERS += basic.h Exception.h MessageService.h
    24. SOURCES += basic.cpp Exception.cpp MessageService.cpp
    To copy to clipboard, switch view to plain text mode 
    i run qmake, i run nmake and get a .dll (but no .lib)
    Want a .dll (and its import lib) only? Use "CONFIG += dll".

    What's the point of "target.path = ../_libs" ? AFAIK the install mechanism is rarely used on windows (binary installer are fvored) and besides doesn't make much sense here... Don't you think "DESTDIR = ../_libs" would be better ?
    Current Qt projects : QCodeEdit, RotiDeCode

  14. #14
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: build lib and dll with qmake

    thanx for the hint. i tried CONFIG += dll but it still does
    not work. the dll is build but still the .lib is not build.
    but anyway the compiler tries to copy the .lib which is not build. do i have to
    build an static version first?

    Generieren von Code...
    link /LIBPATH:"c:\Qt\4.1.4-com\lib" /NOLOGO /INCREMENTAL:NO /INCREMENTAL:NO /DLL /OUT:"release\model.dll" @C:/DOKUME~1/jh/LOKALE~1/Temp\nm21.tmp
    copy /y "release\model.lib" "c:\01. - Arbeit\C++\shared_libs\basic\libs\model.lib"
    Das System kann die angegebene Datei nicht finden.
    copy /y "release\model.dll" "c:\01. - Arbeit\C++\shared_libs\basic\libs\model.dll"
    1 Datei(en) kopiert.
    regards,
    jh
    Last edited by jacek; 4th March 2007 at 14:46. Reason: changed [code] to [quote]

  15. #15
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    Quote Originally Posted by jh View Post
    thanx for the hint. i tried CONFIG += dll but it still does
    not work. the dll is build but still the .lib is not build.
    but anyway the compiler tries to copy the .lib which is not build. do i have to
    build an static version first?

    Generieren von Code...
    link /LIBPATH:"c:\Qt\4.1.4-com\lib" /NOLOGO /INCREMENTAL:NO /INCREMENTAL:NO /DLL /OUT:"release\model.dll" @C:/DOKUME~1/jh/LOKALE~1/Temp\nm21.tmp
    copy /y "release\model.lib" "c:\01. - Arbeit\C++\shared_libs\basic\libs\model.lib"
    Das System kann die angegebene Datei nicht finden.
    copy /y "release\model.dll" "c:\01. - Arbeit\C++\shared_libs\basic\libs\model.dll"
    1 Datei(en) kopiert.
    I've never used MSVC but by comparing the two build commands (your own and the above one) it is obvious than the /implib switch is missing (BTW M$ switch syntax sucks a great deal... :P ). If you're sure that this hasn't been caused by a manipulation of yours you should report the bug to Trolltech and waiting for a fix you can always try this workaround :
    Qt Code:
    1. QMAKE_LINK_SHLIB_CMD += /implib:$${TARGET}.lib
    To copy to clipboard, switch view to plain text mode 

    Hope this helps.
    Last edited by jacek; 4th March 2007 at 14:46. Reason: changed [code] to [quote]
    Current Qt projects : QCodeEdit, RotiDeCode

  16. The following user says thank you to fullmetalcoder for this useful post:

    jh (4th March 2007)

  17. #16
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: build lib and dll with qmake

    I've been running into this same problem. I created a project using MinGW, and now want to build with MSVC. Below is what I added to the .pro file, and is working for me (non of the above did).

    win32-msvc* {
    LIBS += Advapi32.lib Setupapi.lib
    CONFIG -= dll
    CONFIG += shared static
    }

    The LIBS was required as the "difference" of mingw.

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.