Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Static linking for windows
QtWS25 Last Chance

Static linking for windows

Scheduled Pinned Locked Moved General and Desktop
24 Posts 12 Posters 36.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dalaing
    wrote on last edited by
    #10

    It looks like you've had two problems with the process.

    The first problem has already been covered, by other people in here and in the documentation. From the docs:

    bq. Also, we have used nmake in all the examples, but if you use MinGW you must use mingw32-make instead.

    I'm not sure it counts as a deep flaw if the documentation is unable to prevent people from skimming :)

    The second problem is a typo, indicated by the error message:

    bq. creating symbolic link mkspecs/default/win32-G++’ to win32-G++’: No such file or directory

    If you try again with configure -platform win32-g++ <all of your other configure options> you'll probably have more luck. I believe all of the options to configure are case sensitive.

    Hopefully that helps.

    David Laing
    Location API team
    Qt Mobility

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sleam
      wrote on last edited by
      #11

      Thank you for your feedback david, but I got a bit confued, and I think the forum is the fault:

      bq. creating symbolic link mkspecs/default/win32-G++’ to win32-G++’: No such f
      ile or directory

      The text i entered into the quote was not: "...win32-G+..." it was: "...win32-G++..."

      So, I cannot really be sure what you mean david, the forum does not correctly reflect what you and I wrote.

      Moderators, please fix this?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #12

        Hi,

        if all you need is a static build of Qt, done with mingw, do the following:

        extract Qt-...-src.zip (that is without any temporary file that mighjt disturb) :)

        Change path-to-qt\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

        cd %qtdir%
        configure -static -release -no-exceptions -[other parameters like -mmx -sse -sse2 -3dnow etc...]
        mingw32-make sub-src [here you can make some coffee etc.. it will take some time]
        @

        If you use webkit, you have to change the webkit pri file also:
        \src\3rdparty\webkit\ WebKit.pri:
        CONFIG += staticlib

        For builds after making the changes in the config files, I used a batch file:
        @set QTDIR=D:\Developement\Qt\2010.04\qt_static
        set PATH=D:\Developement\Qt\2010.04\qt_static\bin
        set PATH=%PATH%;D:\Developement\Qt\2010.04\bin;D:\Developement\Qt\2010.04\mingw\bin
        set PATH=%PATH%;%SystemRoot%\System32
        set QMAKESPEC=win32-g++

        mingw32-make confclean
        configure.exe -release -confirm-license -qt-libpng -opensource -no-incredibuild-xge -process -static
        mingw32-make
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #13

          Could you please change the topic back to its original text. The forum does not have a bug.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mgran
            wrote on last edited by
            #14

            Looks like the forum wants to make an underline (uses a + for markup) instead of letting you write "g++" in a block quote.

            Not a bug - just a very eager feature ;) We shall have a look.

            Project Manager - Qt Development Frameworks

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #15

              If you are on a unixoid OS it might be a typo. Instead of

              @-platform win32-G++@

              use

              @-platform win32-g++@

              with a lower case g not a capital G.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #16

                Hi, I created a wiki page on how to create static libaries for windows with gcc:
                "BuildStaticQtForWindowsWithGcc":http://developer.qt.nokia.com/wiki/Category:QtDevelopment::General::BuildStaticQtForWindowsWithGcc

                I hope it might help.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cezary Tomczak
                  wrote on last edited by
                  #17

                  If anyone is trying to compile libraries for Qt 4.7.1 with mingw read this:

                  Qt libraries 4.7.1 for Windows do not compile with mingw, there are errors in src/declarative/qml/ in 5 files, they use "intptr_t" which is defined in "stdint.h" as "int", which generates an error in casts. I've looked on gitorious qt 4.7.2 and it has been fixed, "intptr_t" has been replaced with "uintptr" which is defined in qglobal.h as "QIntegerForSizeof[void*]::Unsigned" and works fine.

                  The fix: search for "intptr_t" in src/declarative/qml and replace it with "uintptr" (should find 5 files).

                  After the the search & replace libs compile with no errors.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Cezary Tomczak
                    wrote on last edited by
                    #18

                    Gerolf Reinwardt: I've been compiling qt libs yesterday, I didn't know about that wiki page, it's been a lot of pain.

                    My compile solution differs a little from the one in wiki, but it works, so it should be ok, right? Here are the differences:

                    • I deleted the whole lib/ directory along with fonts and readme.
                    • I didn't touch bin/ directory, all files are still there
                    • win32-g++/qmake.conf, I didn't add "DEFINES += QT_STATIC_BUILD"
                    • also not this: bin\qmake.exe projects.pro QT_BUILD_PARTS=”libs” JAVASCRIPTCORE_JIT=”yes”

                    But i've added more arguments in configure like -no-make examples -no-make tools etc. So only lib/ and qmake/ have been compiled.

                    And in qt creator I've added this static version and provided qmake from the qmake/ directory, not the bin/ directory.

                    There are more articles about building qt static:

                    http://www.qtcentre.org/wiki/index.php?title=Building_static_Qt_on_Windows

                    http://www.qtcentre.org/wiki/index.php?title=Building_static_Qt_on_Windows_with_MinGW

                    http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/

                    Formortals.com provides cflags for size-optimized libraries, but they don't work: -Os -mpreferred-stack-boundary=2 -finline-small-functions -momit-leaf-frame-pointer (I got compile errors)

                    Btw. I've been compiling with mingw 4.5.0 (g++ version), the mingw included in qt sdk is 4.4.0. I compared them by compiling project with shared libraries and the executable created with 4.5.0 was 85 KB, compare it to 130 KB with 4.4.0. But there is an additional .dll required when compiling with 4.5.0 (libstdc++.dll which is 850 KB), 4.4.0 only requires mingwm10.dll and libgcc_s_dw2-1.dll. When compiling statically I only used 4.5.0 so can't compare them, which ones generates smaller exe.

                    But here here is some info for my program, using 4.5.0 compiled staticaly: using CORE, GUI and DECLARATIVE libraries, the compiled exe is 8.7 MB, after upx'ing it compresses to: 3.2 MB.

                    There is no difference when running the 8.7 MB exe or the upx'ed 3.2 MB exe, they both execute n less than a second. Compare it with exe with the dlls: it executes 3-4 seconds! (tested on old one computer - 1.5 GHz 1 core). Yes it takes so long to load these dlls, together the dlls size is 23.3 MB. I use only core, gui and declarative but they require others too when running the program: QtNetwork4.dll, QtScript4.dll, QtSql4.dll, QtXmlPatterns4.dll - so together it is 23.3 MB. It is not so bad when using an NSIS installer (nsis.sourceforge.net), it can pack it using lzma to 7.2 MB. But using static libraries and upx gives us 3.2 MB which is 2.5x less.

                    Btw. when you disable not needed libaries, as I was compiling my app disabling qtwebkit and others (see configure.exe arguments) the lib/ and qmake/ can compile in less than 30 minutes (using mingw 4.5.0).

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      niby
                      wrote on last edited by
                      #19

                      You can use VC Compiler instead of MinGW.
                      That's should been fastest.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #20

                        From my experiences, MSVC and gcc compiler are not so different in time.
                        Regarding the mingwm10.dll and libgcc_s_dw2-1.dll libraries, thta's why I added LFLAGS = -static -static-libgcc which adds these as static libraries.
                        I know, there are several pages describing statically build, but I also tried long time to get it compiled, until I had all Info I needed :-). That's why I created the page describing my steps one after the other (I left the round trips out).
                        It's clear, that the dll size is much bigger, as it contains everything, and you exe only what you need. So static executables are always faster and smaller. But they have more effort in fixing and maintaining, as you can't fix just one part, you always have to distribute all, incl the Qt code (as it's in the exe) and don't get fixes, just by changing the Qt dlls.

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • . Offline
                          . Offline
                          ..k1..
                          wrote on last edited by
                          #21

                          Thank You Cezary Tomczak!

                          this:
                          [quote author="Cezary Tomczak" date="1291037300"]

                          • I deleted the whole lib/ directory along with fonts and readme.
                          • I didn't touch bin/ directory, all files are still there
                          • win32-g++/qmake.conf, I didn't add "DEFINES += QT_STATIC_BUILD"
                          • also not this: bin\qmake.exe projects.pro QT_BUILD_PARTS=”libs” JAVASCRIPTCORE_JIT=”yes”
                            [/quote]

                          helps me a lot, after days tearing out my hair.

                          http://hunix.info/webimg/bugStop.jpg

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            Billa
                            wrote on last edited by
                            #22

                            Could You Explain Even more on this
                            [quote author="Gerolf" date="1290842572"]Hi,

                            if all you need is a static build of Qt, done with mingw, do the following:

                            extract Qt-...-src.zip (that is without any temporary file that mighjt disturb) :)

                            Change path-to-qt\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

                            cd %qtdir%
                            configure -static -release -no-exceptions -[other parameters like -mmx -sse -sse2 -3dnow etc...]
                            mingw32-make sub-src [here you can make some coffee etc.. it will take some time]
                            @

                            If you use webkit, you have to change the webkit pri file also:
                            \src\3rdparty\webkit\ WebKit.pri:
                            CONFIG += staticlib

                            For builds after making the changes in the config files, I used a batch file:
                            @set QTDIR=D:\Developement\Qt\2010.04\qt_static
                            set PATH=D:\Developement\Qt\2010.04\qt_static\bin
                            set PATH=%PATH%;D:\Developement\Qt\2010.04\bin;D:\Developement\Qt\2010.04\mingw\bin
                            set PATH=%PATH%;%SystemRoot%\System32
                            set QMAKESPEC=win32-g++

                            mingw32-make confclean
                            configure.exe -release -confirm-license -qt-libpng -opensource -no-incredibuild-xge -process -static
                            mingw32-make
                            @[/quote]

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #23

                              you can have a look at the wiki: "How to build a static Qt version for Windows with GCC":http://developer.qt.nokia.com/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                cppdeveloper
                                wrote on last edited by
                                #24

                                The solution for me is the following currently:

                                1. Download Qt SDK 4.7.0 (4.7.1 - 4.7.3 not working):

                                ftp://ftp.qt.nokia.com/qtsdk/qt-sdk-win-opensource-2010.05.exe

                                (from ftp://ftp.qt.nokia.com/qtsdk)

                                1. Statically build Qt according to instructions:

                                http://doc.trolltech.com/4.7.1/deployment-windows.html#static-linking

                                1. Statically build your apps according to the above instructions.

                                I hope these will help you.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved