Important: Please read the Qt Code of Conduct -

How to build static programs in Qt

  • Hi,

    I'd like to make my Qt compilation static ( no need to .dll files to run the .exe generated file) . I use MinGW and Qt 4.8.6 .

    I found some instructions about changing .conf files but I'm afraid it would take me a lot of time to correct it if I use the wrong one.

    So basically here are two versions :

    If I suppose the first one is good for me (if it is not, please tell me !) , I should do these changes :

    " edit the file Path-To-Qt-SDK\qt_static\mkspecs\win32-g+.conf and add the bold (with * ) marked stuff
    QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
    QMAKE_LFLAGS = -static -static-libgcc …

    edit Path-To-Qt-SDK\qt_static\qmake\Makefile.win32-g++
    LFLAGS = -static -static-libgcc …

    edit Path-To-Qt-SDK\qt_static\src\3rdparty\webkit\WebKit.pri
    add 'CONFIG = staticlib* on the top "

    So does "qt_static\mkspecs\win32-g+.conf" mean "qt_static\mkspecs\win32-g++\qmake.conf " or "qt_static\mkspecs\win32-g++-4.6\qmake.conf" ??

    And if it is the first one ( I mean "qt_static\mkspecs\win32-g++\qmake.conf " ) , should I replace the lines beginning with
    DEFINES= "
    or should I keep them and add new ones ?

    And these "..." in "LFLAGS = -static -static-libgcc …" , should I keep it ??

    and then I have :
    "edit Path-To-Qt-SDK\qt_static\qmake\Makefile.win32-g++
    LFLAGS = -static -static-libgcc …"

    Here there is no doupt about the file (thank God) , so should I replace the line 30 "LFLAGS = -static-libgcc -s" with "LFLAGS = -static -static-libgcc …" ?? , and should I keep this "..." ?

    last but not least , we have :

    "edit Path-To-Qt-SDK\qt_static\src\3rdparty\webkit\WebKit.pri
    add 'CONFIG = staticlib* on the top "

    Unfortunately, there is no "WebKit.pri" in that location , I find it in "Path-To-Qt-SDK\qt_static\src\3rdparty\webkit\Source" , is it the right one ??

    And if itsn't , what would be the right one ?

    And please tell me how to add 'CONFIG = staticlib* on the top', does it mean I have to add "'CONFIG = staticlib*" in the beginning of the file, with that "*" ??

    Please I need answers from people who know precisely how to solve this issue, and forgive me about the need of details because I'm really tired of compiling and recompiling with no result and I'm still beginner.

    And after answering these questions , I'll be happy if you give me the right commands to enter in the Qt Command prompt.

    Thank you very much in advance !!

  • Lifetime Qt Champion


    First thing: do you really need webkit ? If no, then don't build it.

    Second thing: to ensure that the static build is working start by doing a standard static build i.e. call configure -static.

    Third thing: are you aware of the license implications of a static build ?

    1. No I don't need webkit.
    2. I used standard static build before, and it worked successfully, the executable generated file works on my computer, but not in other computers (libgcc is not found or something like that). Now I deleted and installed again MinGW, Qt and Qt Creator.
    3. Yes, I'm aware.

  • Lifetime Qt Champion

    1. Good, then just disable the build of webkit, it will save you time and space.
    2. That's normal, these are runtime libraries like the Visual Studio runtimes are needed when you deploy an application built with Visual Studio.

    The file is win32-g++/qmake.conf and yes change the lines.

    I'd also recommend an out of source build, since you are toying with the build settings. If something goes wrong you can simply nuke the build folder and start again otherwise you have to call make confclean each time before you reconfigure.

  • @SGaist Yes ! , it worked, thank you very much !

Log in to reply