How To Build QT Application Statically

|

Static Installation of Qt 4.6.2 On Windows And QT Application Deployment


Recently I had to deploy an application I created using Qt on Windows. In order to keep things simple by only having a few files to deploy, i.e. a stand-alone executable with the associated compiler specific DLLs, I had to build everything statically. After having a static installation of QT in my PC, I was able to build my application.

I am going to describe the procedure below, because I spent a few hours until I finally succeed.

  1. First of all we have to download and install:
    a.    minGW from here.
    b.    QT libraries Windows from here.


  2. When we have finished with the above installations, we have to add minGW’s bin folder path into system PATH. The path is usually C:\MinGW\bin.

    a. Right click -> My Computer
    b. Properties -> Advanced Tab
    c. Environment Variables button
    d. We append the following for PATH -> ;C:\MinGW\bin\


  3. The next step is to edit mkspecs (c:\Qt\4.6.2\mkspecs\win32-g++\qmake.conf) by finding QMAKE_LFLAGS and add –static:

    QMAKE_LFLAGS = -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc


  4. Now we open a command prompt (Start->Run->”cmd” ) and go to C:\Qt\ 4.6.2 or wherever our Qt is installed.


  5. We initialize QMAKESPEC variable by typing:

    set QMAKESPEC=win32-g++


  6. Next we type in our platform specific configuration option (inside C:\Qt\4.6.2). At this point we suppose that we also need sqlite support, so we use:

    configure -static -release -no-exceptions -qt-sql-sqlite



    After issuing the command QT will ask about the edition we are going to use. If we use the Open Source Edition, we type ‘o’ and press enter:

    C:\Qt\4.6.2>configure -static -release -no-exceptions -qt-sql-sqlite
    Which edition of Qt do you want to use ?
    Type 'c' if you want to use the Commercial Edition.
    Type 'o' if you want to use the Open Source Edition.
    >o


    Next we have to accept the terms of the license by typing ‘y’:

    This is the Qt for Windows Open Source Edition.
    
    You are licensed to use this software under the terms of
    the GNU Lesser General Public License (LGPL) version 2.1
    or the GNU General Public License (GPL) version 3.
    
    Type '3' to view the GNU General Public License version 3 (GPLv3).
    Type 'L' to view the Lesser GNU General Public License version 2.1 (LGPLv2.1).
    Type 'y' to accept this license offer.
    Type 'n' to decline this license offer.
    
    Do you accept the terms of the license?
    >y


    Finally the configuration step will start and will take some time, depending on the system.

  7. When the configuration step completes we issue:

    mingw32-make sub-src


    which may take a while…(you can have a coffee, or two….)…

  8. Now the installation process has been completed.

We can now build our application.

In order to link the static libraries in our application we:
• Open a command prompt and go to the project’s folder.
• We issue:

set QMAKESPEC=win32-g++
qmake -project
qmake *.pro
mingw32-make clean
qmake -config release

• In the .pro file of your project, make sure we include this line:

CONFIG += static

• Now we have the application’s executable, which we can deploy on a PC hich does not have QT installed.
so that it will compile the libraries statically.
• If we also need the SQL library, we add:

QT += sql

in the .pro file.
• And finally we build the application by issuing:

mingw32-make


Trackback 0 And Comment 0
prev | 1 | 2 | 3 | 4 | 5 ... | 70 | next