March 8, 2012

Shabla Shabla
Lab Rat
12 posts

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 [qt-project.org] and this [formortals.com] as a reference and came up with these steps :

  1. 1) Edit <QTDIR>\mkspecs\win32-g++\qmake.conf:
  2.  
  3.     QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
  4.    
  5.     QMAKE_LFLAGS = -static -static-libgcc -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
  6.    
  7.     DEFINES += QT_STATIC_BUILD
  8.  
  9.    
  10. 2) Edit <QTDIR>\qmake\Makefile.win32-g++
  11.  
  12.     LFLAGS      = -static -static-libgcc -s
  13.    
  14.    
  15. 3) Configure Qt for static linking: go to <QTDIR> and run this command (it should take 5-10 minutes):
  16.  
  17. 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
  18.  
  19. 4) Build it. This is gonna take a while (2-3 hours).
  20. 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) :

  1. INCLUDEPATH += "C:/dev/libs/qserialdevice-2.0/include"
  2. 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 !

2 replies

March 9, 2012

kuzulis kuzulis
Robot Herder
360 posts

Two ways:
1. You can build a statically QSerialDevice, edit src.pro

  1. #CONFIG += dll
  2. 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.

March 9, 2012

Shabla Shabla
Lab Rat
12 posts

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

 
  ‹‹ Qt and libQxt      QGLViewer - Depthbuffer z distance ››

You must log in to post a reply. Not a member yet? Register here!