Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Static linking for windows

    General and Desktop
    12
    24
    34573
    Loading More Posts
    • 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.
    • S
      sleam last edited by

      Hi, I have been developing on mobile devices so far, and today I tried to port my application to windows, but this was no easy task..

      I tried to follow this guide:
      "http://doc.qt.nokia.com/4.7/deployment-windows.html#static-linking
      ":http://doc.qt.nokia.com/4.7/deployment-windows.html#static-linking
      Its just terrible.. I does not explain anything, I had to find out things by google, and now I am stuck..

      First thing:
      cd C:\path\to\Qt
      configure -static <any other options you need>

      That was not easy, solution was:
      configure -static -platform win32-g++
      I hope this was right?

      Anyway, the next step is:
      nmake sub-src
      This gives me:
      C:\Qt\4.7.0>namke sub-src
      'namke' is not recognized as an internal or external command,
      operable program or batch file.

      What now? Why is the guide not telling me all I need to know, namke is not to be found..
      I installed this: qt-win-opensource-4.7.0-mingw.exe

      Any help please? :)

      1 Reply Last reply Reply Quote 0
      • M
        mabrand last edited by

        mingw32-make (not nmake) is the "make" command on win32-g++ (MinGW).

        But, you might want to look at mingw-cross-env which includes Qt and builds all static libs.

        "http://mingw-cross-env.nongnu.org/":http://mingw-cross-env.nongnu.org/

        1 Reply Last reply Reply Quote 0
        • S
          sleam last edited by

          Thank you, but running "mingw32-make sub-src" still gets me nowhere..

          1 Reply Last reply Reply Quote 0
          • S
            sleam last edited by

            Nobody knows how to accomplish this with a few simple commands ? Do I really have to waste hours on research just for this? Qt is so good at everything else, why not when it comes to deploying the code ?

            For anyone else following this some day: This link looks good: http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/
            But it fails here:
            bq.
            Open a command-line window appropriate for your compiler.
            GCC: Open the command prompt (Start –> Run –> “cmd”), then run “mingwvars.bat”. For example, if GCC is installed in “c:\MinGW”, then enter the command: “c:\MinGW\mingwvars.bat“
            bq.
            there is no mingwvars.bat file to be found.

            1 Reply Last reply Reply Quote 0
            • M
              mabrand last edited by

              Have you tried mingw-cross-env yet?

              1 Reply Last reply Reply Quote 0
              • S
                sleam last edited by

                No, I have not figured out how to use it, and there is no guides for windoes.
                I have tried this:
                Downloaded : http://sourceforge.net/projects/mingw/files/
                Installed it and selected MSYS and and the C++ compiler.
                I then opened msys.bat and did this:
                @
                $ configure -release -nomake examples -nomake demos -no-exceptions -no-qt3supp
                ort -no-scripttools -no-openssl -no-webkit -no-phonon -no-sql-sqlite -qt-libjpe
                g -qt-zlib -qt-libpng -static -platform win32-G++
                @

                but that retuned this:

                Creating qmake. Please wait...
                rm: cannot remove directory mkspecs/default': Is a directory ln: creating symbolic link mkspecs/default/win32-G++' to `win32-G++': No such f
                ile or directory
                g++ -c -o project.o -DQMAKE_OPENSOURCE_EDITION -I. -Igenerators -Igenerators/un
                ix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian -I/c/qt/4.7.0/includ
                e -I/c/qt/4.7.0/include/QtCore -I/c/qt/4.7.0/src/corelib/global -I/c/qt/4.7.0/sr
                c/corelib/xml -I/c/qt/4.7.0/tools/shared -DQT_NO_PCRE -DQT_BUILD_QMAKE -DQT_BOOT
                STRAPPED -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL -
                DQT_NO_COMPRESS -I/c/qt/4.7.0/mkspecs/win32-G++ -DHAVE_QCONFIG_CPP -DQT_NO_THREA
                D -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT project.cpp
                project.cpp: In member function 'QStringList& QMakeProject::values(const QString
                &, QMap<QString, QStringList>&)':
                project.cpp:3024:51: error: cannot convert 'wchar_t*' to 'CHAR*' for argument '1
                ' to 'BOOL GetComputerNameA(CHAR*, DWORD*)'
                make.exe: *** [project.o] Error 1

                1 Reply Last reply Reply Quote 0
                • M
                  mabrand last edited by

                  No, I asked if you tried this:

                  http://mingw-cross-env.nongnu.org/

                  This is a cross building environment for unix targeting MinGW/Windows. Check out the website.

                  1 Reply Last reply Reply Quote 0
                  • I
                    ivan.todorovich last edited by

                    use make instead of nmake.
                    that should do it

                    o_o Sorry for my rusted english.

                    1 Reply Last reply Reply Quote 0
                    • S
                      sleam last edited by

                      Thank you for all your input, but this continues to be Qt's biggest flaw to date, this limits our development process so much that we are considering moving to another language.

                      We feel really tricked here, Qt is such a nice language that we came to love it very easily, but when we try to actually deploy our code, there is no documentation on this very crucial step for us. (Well, there is documentation, but it is deeply flawed and does not at all reflect the tools that are delivered to developers).

                      1 Reply Last reply Reply Quote 0
                      • D
                        dalaing last edited by

                        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 Reply Quote 0
                        • S
                          sleam last edited by

                          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 Reply Quote 0
                          • G
                            giesbert last edited by

                            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 Reply Quote 0
                            • G
                              goetz last edited by

                              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 Reply Quote 0
                              • M
                                mgran last edited by

                                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 Reply Quote 0
                                • G
                                  goetz last edited by

                                  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 Reply Quote 0
                                  • G
                                    giesbert last edited by

                                    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 Reply Quote 0
                                    • C
                                      Cezary Tomczak last edited by

                                      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 Reply Quote 0
                                      • C
                                        Cezary Tomczak last edited by

                                        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 Reply Quote 0
                                        • N
                                          niby last edited by

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

                                          1 Reply Last reply Reply Quote 0
                                          • G
                                            giesbert last edited by

                                            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 Reply Quote 0
                                            • First post
                                              Last post