Qt Static and 3rd party static library



  • Hi, up to now I've been building my application in dynamic build and I'm using QSerialDevice, distributing it with all the needed dlls. I'm building with Mingw using QtCreator on Windows XP. Now I would like to build it statically so that I don't need all those dlls anymore (libgcc_s_dw2-1.dll, mingwm10.dll, QtCore4.dll, QtGui4.dll, and my 3rd party library SerialPort.dll).

    After many research I finally got Qt to compile in static, but I didn't set the parameters right with configure so I'm going to rebuild it again. Since it takes a while I'd like to get it right before I try again.

    I used "this":https://qt-project.org/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc and "this":http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/ as a reference and came up with these steps :

    @1) Edit <QTDIR>\mkspecs\win32-g++\qmake.conf:

    QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
    
    QMAKE_LFLAGS = -static -static-libgcc -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
    
    DEFINES += QT_STATIC_BUILD
    
    1. Edit <QTDIR>\qmake\Makefile.win32-g++

      LFLAGS = -static -static-libgcc -s

    1. Configure Qt for static linking: go to <QTDIR> and run this command (it should take 5-10 minutes):

    configure -static -debug-and-release -opensource -confirm-license -no-opengl -platform win32-g++ -no-phonon -no-audio-backend -no-webkit -no-rtti -no-sql-sqlite -no-qt3support -no-libtiff -nomake examples -nomake demos -no-exceptions -no-stl -no-scripttools -no-openssl -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique

    1. Build it. This is gonna take a while (2-3 hours).
      mingw32-make.exe@

    My question is as follow: do I need to do something special for my 3rd party library (QSerialDevice) to be added to the exe (no need for the SerialPort.dll) ? Here are the lines related in my Qt Creator .pro (replace debug with release for that version) :
    @INCLUDEPATH += "C:/dev/libs/qserialdevice-2.0/include"
    LIBS += -L"C:/dev/libs/qserialdevice-2.0/src/debug" -lSerialPort@
    and my "C:\dev\libs\qserialdevice-2.0\src\debug" folder contain both a SerialDevice.a and SerialDevice.dll.

    Now when I build my program with Qt dynamic it needs the SerialPort.dll, so what are the steps to do in order to remove this dependency ?

    Thanks !



  • Two ways:

    1. You can build a statically QSerialDevice, edit src.pro
      @
      #CONFIG += dll
      CONFIG += staticlib
      @

    2. You can directly use the class library, connecting them to your project through the *.pri,
      see /tests/guiapp/guiapp.pro

    The easiest - way to #2.



  • Tried the 2nd way and it works perfectly, thank you !
    I also built Qt static with the above steps and everything works fine !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.