Home > Nokia, Open source, Qt > Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler

Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler

Qt can easily be made into a smaller library than the default install provides.

This article will show you how to build Qt, the popular C++ framework from Nokia, so that it is both small and, if you prefer, available for static linking. Your Qt applications will be smaller, possibly faster, and can be distributable as a single executable.

Also answered: How small can Intel’s C++ compiler make a large library? How does Microsoft fare? Three compilers (settings tuned for small file output) and their resulting code size is compared.

A nice table of contents so that you can see what you’re getting into:

* optional

  1. Download the latest Qt source code and put it in its own directory.
  2. *Modify the compiler flags for use when building Qt.
  3. Open a command-line window for your compiler.
  4. Configure.
  5. Compile.
  6. *If you want to use static linking, modify your Qt project.

A few things to keep in mind before we get started:

Before getting started, you may wish to install a separate compiler. The full Qt SDK comes with G++3 as of this writing (G++ is the C++ compiler that comes with GCC). It works, but G++4 generates better code. I recommend the TDM release. Microsoft Visual Studio Intel’s compiler are also very capable. This article covers them all.

G++ and the Intel compiler are compatible. Either compiler can link to libraries built with the other compiler.
Microsoft’s C++ compiler is incompatible with the other two, so if you build Qt with it, you are stuck with Microsoft’s compiler for the whole project. This isn’t necessarily bad.  Visual C++ is a fine compiler, and finishes compiling Qt noticeably faster than the other two.

GCC is available free of charge, source code included.
Microsoft’s compiler is available for free in their “Express edition“. It is more or less fully functional.
Intel’s compiler, however, is only available free of charge on the Linux platform, and even then only for non-commercial software development. That said, it is widely thought of as producing the fastest code.

With that out of the way, let’s begin:

  1. Download the latest Qt source code and put it in its own directory.
    You can get the entire SDK or  just the source code. Either way, each compilation should be in a separate folder.
  2. *Modify the compiler flags for use when building Qt.
    You’ll be changing one line of the file “make.conf” in the “mkspecs” folder. If Qt in the “C:\Qt” folder, for example, then the file is “C:\Qt\mkspecs\COMPILER\make.conf”, where COMPILER is :
    win32-g++” for GCC
    win32-icc” for the Intel compiler
    win32-msvc2008” for the Microsoft compiler (replace 2008 with the year of release).In all three cases, you will edit the line: “QMAKE_CFLAGS_RELEASE =“, changing the contents after the equals sign to the following:

    1. For GCC: -Os -momit-leaf-frame-pointer
    2. For ICC: -Os -Oy
    3. For VC++: -O1 -Og  -GL -MD

    For example, my ICC line shows: “QMAKE_CFLAGS_RELEASE    = -Os -Oy
    You may wish to add other optimizing flags as well. See your compiler’s documentation.

  3. Open a command-line window appropriate for your compiler.
    1. 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
    2. Microsoft Visual Studio: Look for the “Visual Studio 2008 Command Prompt” entry in your start menu. It is usually found under “Programs\Microsoft Visual Studio 200X\Visual Studio Tools\”. The Express versions should be similar. Alternatively, search your hard drive for “vcvarsall.bat” and from that folder, run “vcvarsall.bat x86” from the command line.
    3. Intel compiler: Similar to Visual Studio, an icon is provided in your start menu, usually in: “Programs\Intel(R) Software Development Tools\Intel(R) C++ Compiler x.y.z“. Alternatively, find iclvars.bat and from that folder, run “iclvars.bat ia32
  4. Configure Qt.
    Change to the Qt folder. For example, type cd C:\Qt\4.6.3-msvc if you unzipped Qt to C:\Qt\4.6.3-msvc. This folder should have configure.exe within. Run the following long command:
    configure -release  -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite

    1. Add “-platform win32-???” for your compiler. Replace “???” with the name of your compiler, same as in step 2. You can also look for your compiler’s name in the Qt\mkspecs folder. For example, a Microsoft Visual Studio 2008 user would use “-platform win32-msvc2008“.
    2. Add “-static” if you are compiling for static linking (libraries included in your .exe rather than as separate files. This mostly applies to qtcore4.dll and qtgui4.dll)
    3. Add any static functionality your application needs., if you are compiling static For example, -qt-libjpeg -qt-zlib -qt-libpng for JPEG image, ZIP compression, and PNG (which also needs zlib) respectively.  See How to Statically Link Qt4.
    4. Remove “-no-exceptions -no-stl -no-rtti” if you need those C++ features. Note that with -no-stl, you are still able to use the STL, but Qt will not have built-in convenience functions to, for example, set a QVector equal to a C++ vector. That is, you will have to do so manually.
    5. Replace “-release” with “-debug-and-release” if this will be your debug install, too. Do not use -static.
    6. The remaining “-no-foo” options disable various features. See the output of “configure –help” for documentation. You can write this to a file with “configure –help > options.txt“.
  5. Compile Qt.
    After step 4, you will be informed of which command starts the actual compile (usually mingw32-make or nmake).
  6. (static only) Configure your project for use of the static library.

It’s the size that counts and how you use it.

When working towards making Qt (and therefore your projects) small, it is important to have some idea of what each compiler can do. I will compare the sizes of QtCore4.dll (core Qt functionality) and QtGui4.dll (Graphical interface libraries and operating system interface). These two files that are fairly representative of size scaling among Qt libraries, and also happen to be the two most common files needed by Qt applications.

Relative size of Qt libraries from three compilers

Interpretation:

  • ICC’s code size is about the same as GCC’s unoptimized. The sum of both file’s sizes is 11.38MB on both compilers.
  • With appropriate settings, GCC’s compiled Qt code size drops more than 40%, from 11.38MB to only 6.63MB combined.
  • Microsoft Visual C++ handily beats the other compilers, with a library size less than half of ICC’s and about 15% smaller than GCC’s best effort.(Edit: Arik notes that this compilation is still dependent on Microsoft’s msvcrtXX.dll. See his comment below regarding how to eliminate this dependency. This may change the size of your application).

Additionally, Microsoft’s compiler finished the job in about 1/5 the time of ICC and about 1/3 the time of GCC Optimized. I actually ran it twice because I thought it may have aborted without error, because the time difference was so substantial.

Update: I’ve compiled CNB ImageGuide to provide a real application size example. Using G++, executable size is 5.8MB. Using Microsoft C++ 2008 and Arik’s suggestion, it is 3.56MB, or about a 60% difference. I’d like to welcome theories as to why the difference is so substantial.

However:

  • This does not take into account the performance of the resulting libraries, with Intel likely taking the lead.
  • ICC is designed for absolute performance, not small code size.
  • MSVC is not available on most platforms supported by Qt.
  • The author is far more familiar with the compiler flags for G++ than for the other two compilers.  It is possible that a particular combination of options will significantly change the results.

I hope this has been helpful and informative. Communicate any feedback, good or bad, in the comments section.

Repeatability

Everyone is welcome to try to repeat, improve upon, or dispute my results. The settings used follow.

Intel Compiler 11

cflags: -Os -Oy
Qt configuration:
-release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-icc

Microsoft Visual C++ 2008

cflags: -O1 -GL -MD
Qt configuration:
-release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-msvc2008

GCC 4.4.1 default (TDM release 2)

cflags: -O2
Qt configuration:
-release -nomake examples -nomake demos -platform win32-g++

GCC 4.4.1 Optimized

cflags: -Os -mpreferred-stack-boundary=2 -finline-small-functions -momit-leaf-frame-pointer
Qt configuration:
-release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-g++

Edit 27 Jan 2010:

Memory footprint data for both executables (GCC and Microsoft compiled)

Memory footprint for Qt static compiled program using GCC 4.4

Memory footprint - Qt static compiled with GCC 4.4

Memory footprint for Qt static compiled program using Microsoft Visual Studio 2008

Memory footprint - Qt static compiled with MS Visual Studio 2008

Interpretation: The Microsoft-compiled static Qt executable seems to use about 10% less memory than the GCC compiled one.

Qt Creator note: If  you are using Qt Creator for your projects and have compile errors, deselect “use jom instead of nmake” under Tools –> Options –> Projects.

  1. October 12th, 2009 at 04:26 | #1

    Excellent, comprehensive write-up Charles.

    Folks, keep in mind that Qt is released by Nokia on the following platforms:

    * Qt for Linux/X11 – Qt for X Window System (Unix / Linux)
    * Qt for Mac OS X – Qt for Apple Mac OS X
    * Qt for Windows – Qt for Microsoft Windows
    * Qt for Embedded Linux – Qt for embedded platforms (PDA, Smartphone, etc.)
    * Qt for Windows CE – Qt for Windows CE[11]
    * Qt for Symbian S60
    * Qt for Maemo (Nokia N900)

    That, by itself, says alot.

  2. delme-after-fix
    November 10th, 2009 at 11:27 | #2

    in text
    “You can get the entire SDK or just the source code. Either way, each compilation should be in a separate folder.”

    “entire SDK” is http://qt.nokia.com/downloads
    “entire SDK” should be http://download.qt.nokia.com/qtsdk/

    “just the source code” is http://download.qt.nokia.com/qtsdk/
    “just the source code” should be http://get.qt.nokia.com/qt/source/
    ———————————————–
    Thanks for great articles! :)

  3. Arik
    November 30th, 2009 at 14:16 | #3

    Thanks a lot for your tutorial.

    For anyone who is interested in a compiling fully static libraries for msvc (no msvcrtXX.dll dependence), you need change the QMAKE_CFLAGS_RELEASE from -MD to -MT, and add /NODEFAULTLIB:”MSVCRT” to the QMAKE_LFLAGS_RELEASE.

  4. December 4th, 2009 at 09:19 | #4

    @Arik
    Thanks, I’ve added this information to the article. Very good to know.

  5. fenerista
    December 6th, 2009 at 11:54 | #5

    Can anybody suggest me a configure with parameters for debug and static install ?

    For my debug install, I did this : configure -debug-and-release -platform win32-msvc2008 as read your suggestion(Replace “-release” with “-debug-and-release” if this will be your debug install, too. Do not use -static.)

    and what about static install ? I think if it is a relase install better ?
    configure -release -platform win32-msvc2008

    -qt-libjpeg -qt-zlib -qt-libpng these parameters, are they important ? If I dont add these paremeteres, Is it impossible to statically link for these files ?(jpeg, png…) You told about that on this link:

    http://www.formortals.com/how-to-statically-link-qt-4/

    and what is this ?

    “For anyone who is interested in a compiling fully static libraries for msvc (no msvcrtXX.dll dependence), you need change the QMAKE_CFLAGS_RELEASE from -MD to -MT, and add /NODEFAULTLIB:”MSVCRT” to the QMAKE_LFLAGS_RELEASE.”

    the lines must be like these ?

    QMAKE_CFLAGS_RELEASE = -O2 -MT

    QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO (that’s default)
    QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /NODEFAULTLIB:”MSVCRT” ? I dont know what it should be like ?

  6. fenerista
    December 6th, 2009 at 12:01 | #6

    I just enter on vs 2008 command prompt “configure” for debug install It saw platform as “win32-msvc2008″ automaticly. and I will see what’s going on when I made nmake.

  7. December 7th, 2009 at 11:18 | #7

    @fenerista
    The following is from my current notes that I use when making a new build:

    G++ COMPILER:
    1) Change \mkspecs\win32-g++\qmake.conf: QMAKE_CFLAGS_RELEASE = -Os -mpreferred-stack-boundary=2 -finline-small-functions -momit-leaf-frame-pointer -march=pentium3 -mtune=core2 -mfpmath=sse
    2) configure -opensource -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -mmx -sse -static -platform win32-g++
    3) mingw32-make

    Microsoft compiler:
    1) Change \mkspecs\win32-msvc2008\qmake.conf: QMAKE_CFLAGS_RELEASE = -O1 -GL -arch:SSE -MT -MP2
    1.5) Add /NODEFAULTLIB:”MSVCRT” /LTCG to QMAKE_LFLAGS_RELEASE
    2) configure -opensource -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -mmx -sse -static -platform win32-msvc2008
    3) nmake

    For non-static builds, as you said, I change “-release” to “-debug-and-release”.
    The -qt-zlib (etc.) I added to ensure the built-in Qt support for these is compiled in. Honestly, I’ve not tested it otherwise.

    Regarding “QMAKE_LFLAGS_RELEASE”, my own is exactly the following:
    QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /NODEFAULTLIB:”MSVCRT” /LTCG

    This is basically the same as the one in your post, so you are right.
    (/LTCG is optional, but will speed up the process as warnings without it indicate)

    I recently built an application in Qt Creator using these settings and it seems to work well.

  8. fenerista
    December 9th, 2009 at 09:03 | #8

    @Charles N. Burns,
    Thank you very much sir! for quick reply.

  9. fenerista
    December 9th, 2009 at 09:14 | #9

    fenerista
    “I just enter on vs 2008 command prompt “configure” for debug install It saw platform as “win32-msvc2008″ automaticly. and I will see what’s going on when I made nmake.”

    and the result:


    ….
    …..
    j : error LNK2019: unresolved external symbol “protected:
    void __thiscall QWebPage::unsupportedContent(class QNetworkReply *)” (?unsupport
    edContent@QWebPage@@IAEXPAVQNetworkReply@@@Z) referenced in function “public: vi
    rtual void __thiscall WebCore::FrameLoaderClientQt::download(class WebCore::Reso
    urceHandle *,struct WebCore::ResourceRequest const &,struct WebCore::ResourceReq
    uest const &,class WebCore::ResourceResponse const &)” (?download@FrameLoaderCli
    entQt@WebCore@@UAEXPAVResourceHandle@2@ABUResourceRequest@2@1ABVResourceResponse
    @2@@Z)
    FrameLoaderClientQt.obj : error LNK2019: unresolved external symbol “protected:
    void __thiscall QWebPage::downloadRequested(class QNetworkRequest const &)” (?do
    wnloadRequested@QWebPage@@IAEXABVQNetworkRequest@@@Z) referenced in function “pu
    blic: virtual void __thiscall WebCore::FrameLoaderClientQt::startDownload(struct
    WebCore::ResourceRequest const &)” (?startDownload@FrameLoaderClientQt@WebCore@
    @UAEXABUResourceRequest@2@@Z)
    ..\..\..\..\lib\QtWebKitd4.dll : fatal error LNK1120: 9 unresolved externals
    NMAKE : fatal error U1077: ‘”E:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
    \link.EXE”‘ : return code ’0×460′
    Stop.
    NMAKE : fatal error U1077: ‘”E:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
    \nmake.exe”‘ : return code ’0×2′
    Stop.
    NMAKE : fatal error U1077: ‘cd’ : return code ’0×2′
    Stop.

    D:\Qt\2009.05vs\qt>

    nmake stopped but fortunetely, I can even built qt project in vs studio 2008 after that errors. At forums, saying that the problem is occuring after SP1.

  10. rybolt
    January 15th, 2010 at 17:49 | #10

    thanks for this interesting insight into compilation modes. can you please report the “memory footprint” of the sample ImageGuide related application? the exe size is useful to know, but i am curious how, if any, is the memory footprint affected.

    assumption: when you stated exe size, i am assuming physical size of file on disk.

  11. January 23rd, 2010 at 14:45 | #11

    @fenerista

    The more recent Qt releases have been including 4 files that need to be deleted. They are all temp files. To fix, open explorer, select the “qt” directory, click “search” and look for all files ending with *.tmp, 4 files will be displayed… delete them. Go back to the command prompt and type “nmake” again… Everything should build from then on.

  12. January 27th, 2010 at 07:16 | #12

    Thanx for awesome article! It’s the first time I am able to build Qt myself, and now at least I know what is dynamic and static compilation.

    Also, as for me it is better to compile Qt with -O2 option (for better speed), and then pack it using UPX (http://upx.sourceforge.net/) so user’s application will work as fast as possible.

  13. January 27th, 2010 at 13:52 | #13

    @rybolt
    I’ve added the information you requested, taken from Process Explorer by Mark Russinovich. As a plug for Mark, he’s an author of the Inside Windows series of books, which are great of you want to learn how things really work inside the OS at the data structure level.

  14. January 28th, 2010 at 06:09 | #14

    Watching Qt compilation process, and here is message I can see:
    lib /NOLOGO /OUT:..\..\..\..\lib\QtWebKit.lib @C:\DOCUME~1\…\LOCALS~1\Temp\nm989.tmp
    QtWebKit_pch.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance

    There is QMAKE_LIB entry, maybe it really will be better to add those flags?

  15. Charles
    February 20th, 2010 at 17:55 | #15

    Thanks for this nice article, and the one at http://www.formortals.com/how-to-statically-link-qt-4/

    One thing that you could add is “-prefix /path/to/Qt” so one doesn’t install the static and dynamic to the same place

  16. February 21st, 2010 at 18:27 | #16

    @Aekold
    Keep in mind that more optimization doesn’t necessarily mean more speed. Often, the longer time to load a larger but more optimized library from disk is greater than the performance gain from the more tuned code. The only way to know is to test.

  17. Tomo
    February 24th, 2010 at 09:02 | #17

    Great article, but there’s one thing I can’t find.

    When I compile this way using Qt Creator 1.3 and mingw 4.4, the resulting binary is still dependent on a couple of mingw DLLs.

    How do I tell mingw to statically link it’s own DLLs into the binary?

  18. Dpatel
    February 25th, 2010 at 06:05 | #18

    Thanks Charles for this excellent article on building Qt with optimizations. I really appreciate it!!

  19. March 17th, 2010 at 00:19 | #19

    @Tomo
    Works fine for me in GCC now my executable compressed with upx are around 2 MB.

    But there is one thing that I needed to edit in the mkspec win32-g++ in order to make it mingw fully independent, is the parameter:

    QMAKE_LFLAGS

    I’ve needed to add -static parameter.

    QMAKE_LFLAGS = -enable-stdcall-fixup…. [Change it to]-> QMAKE_LFLAGS = -static -enable-stdcall-fixup….

    Hope that this helps other people.

  20. Przemek
    April 15th, 2010 at 12:46 | #20

    @Aekold

    i use upx it speeds up loading app only if you dont have anti viryus software otherwise it has to load whole dll on start ;/

  21. Adadon
    May 1st, 2010 at 06:26 | #21

    Hi! I’m having serious problems compiling qmake using mingw. When running configure, even if i only use parameter -platform win32-g++, it ends up creating a bad qmake. Every time i launch that qmake, i get a windows access violation error(0xc0000005). I’ve tried adding and removing flags, but i’ve had no luck. I would appreciate it, if someone had a clue about what to do with this. I’m using g++ version 4.5.
    Thanks!

  22. Adadon
    May 1st, 2010 at 06:42 | #22

    Adadon :
    Hi! I’m having serious problems compiling qmake using mingw. When running configure, even if i only use parameter -platform win32-g++, it ends up creating a bad qmake. Every time i launch that qmake, i get a windows access violation error(0xc0000005). I’ve tried adding and removing flags, but i’ve had no luck. I would appreciate it, if someone had a clue about what to do with this. I’m using g++ version 4.5.
    Thanks!

    I’ve solved it! I had to add -enable-auto-import to the makefile.

  23. Sp
    May 4th, 2010 at 02:30 | #23

    I used the following on my windows 7 machine with VS 2008, but got QtCore.lib of 46 MB and the QtGui.lib of 181 MB size:
    1) -O1 -Og -GL -MD
    2) c:\Qt\QtStatic\qt>configure -platform win32-msvc2008 -static -qt-libjpeg -qt-gif
    -debug-and-release -nomake examples -nomake demos -no-qt3support -no-scriptto
    ols -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -
    no-style-cleanlooks -no-style-plastique -no-sql-sqlite.

  24. May 13th, 2010 at 04:24 | #24

    I am using Qt to design the app that will run on a Eurotech.com Moblin Atom Z5xx SBC since Qt is the dev platform for MeeGo but my app causes the following run-time error(s) on the target:
    /home/ume/myapp/: /lib/libc.so.6: version GLIBC_2.9 not found (required by /usr/lib/libQtGui.so.4)
    /home/ume/myapp/: /lib/libc.so.6: version GLIBC_2.11 not found (required by /usr/lib/libQtGui.so.4)
    /home/ume/myapp/: /lib/libc.so.6: version GLIBC_2.10 not found (required by /usr/lib/libQtNetwork.so.4)
    /home/ume/myapp/: /lib/libc.so.6: version GLIBC_2.9 not found (required by /usr/lib/libQtCore.so.4)
    Adding libc-2.11.1.so to /lib (which is what it looks like Qt needs) and replacing libc.so.6 -> libc-2.6.1.so with libc.so.6 -> libc-2.11.1.so causes segmentation faults.
    Is there a way to include libc-2.11.1.so in a static link?
    Thanks,
    Jack Nadelman

  25. Jon
    May 21st, 2010 at 14:12 | #25

    Hi Charles

    Your tutorial is great compared to QT help file, which is rather miserable long winded with no substance.

    I’ve followed your MSVC process but am getting the following error

    gdbmacros.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance

    LINK : fatal error LNK1181: cannot open input file ‘c:\Qt\2010.02.1\qt\lib\QtGui4.lib’

    cl : Command line warning D9024 : unrecognized source file type ‘O1′, object file assumed

    cl : Command line warning D9027 : source file ‘O1′ ignored

    command failed with exit code 1181
    jom 0.8.3 – empower your cores

    command failed with exit code 2

    Not sure if you can help shed some light?

  26. Jon
    May 23rd, 2010 at 11:53 | #26

    Hi folks

    I tried to use the MSVC2008 setting, following exactly what Charles had listed but I get an error under QT versions in QT cretor, the list is as follows, I’m not sure where else I have missed as all the steps were followed, my OS is windows 7 and have 2008 and 2010 installed but reckon that should be ok as I have used the correct path, any suggestion is greatly appreciated:

    Building debugging helper library in C:/Qt/2010.02.1/qt/qtc-debugging-helper/

    Running C:/Qt/2010.02.1/bin/jom.exe distclean…
    C:\Qt\2010.02.1\bin\jom.exe -nologo -j 4 -f Makefile.Debug distclean
    del tmp\obj\debug_static\gdbmacros.o

    [Trimmed -ed]

    release\gdbmacros.dll : fatal error LNK1120: 218 unresolved externals

    command failed with exit code 1120
    jom 0.8.3 – empower your cores

    command failed with exit code 2

  27. May 26th, 2010 at 06:12 | #27

    @Jon
    Jon, disable Jom.

    Under Options –> Projects, deselect “Use jom instead of nmake.”
    Jom, designed to make better use of multiple CPUs, is designed only for the GNU G++ compiler.

  28. vanvu
    June 16th, 2010 at 04:14 | #28

    Hi,
    I encountered the following error when building my Qt app from VS2008:
    Generating Code…
    c:\users\van\documents\visual studio 2008\projects\liveforensics\controlpanel\client-side\tcpworker.cpp(81) : warning C4715: ‘ForensicsControlPanel::TcpWorker::processRequest’ : not all control paths return a value
    Linking…
    qtmain.lib(qtmain_win.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
    qtmain.lib(qtmain_win.obj) : error LNK2005: “public: __thiscall QString::~QString(void)” (??1QString@@QAE@XZ) already defined in QtCore4.lib(QtCore4.dll)
    C:\Users\van\Documents\Visual Studio 2008\Projects\liveForensics\controlPanel\client-side\build\Release\ControlPanel.exe : fatal error LNK1169: one or more multiply defined symbols found

    I use Qt 4.6.2 and My settings is:

    QMAKE_CFLAGS_RELEASE = -O1 -GL -MT
    QMAKE_LFLAGS_RELEASE = /INCREMENTAL:NO /NODEFAULTLIB:”MSVCRT” /LTCG

    configure -release -platform win32-msvc2008 -static -nomake examples -nomake demos -no-qt3support -no-script -no-scripttools -no-multimedia -no-audio-backend -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite

    How can I fix the bug? Thank you very much

  29. Gerald
    July 4th, 2010 at 16:30 | #29

    @ Charles N. Burns

    >> Using G++, executable size is 5.8MB. Using Microsoft C++ 2008 and Arik’s suggestion,
    >> it is 3.56MB, or about a 60% difference. I’d like to welcome theories as to why the
    >> difference is so substantial.

    I came across this detail myself when compiling with msvc2008. I’ve got the same kind
    of executale size like for gcc 4.4.1 compilation when compiling without msvc2008
    project option

    “Whole Program Optimization” set to “No”
    (in Project/Properties/Configuration Properties/”C/C++”/Optimization).

    Once I had set the above option to “Enable link-time code generation (/GL)” the executable’s size decreased.

    Maybe G++ can do this kind of optimization, but I have no idea how.

  30. Mar
    August 15th, 2010 at 23:19 | #30

    @Sp
    Have you figured out what is the reason for this? I’ve stumbled on quite a similar problem.
    However my QtGui.lib is even bigger – 282Mb

    System: Windows 7
    Tools: MSVS2008
    soruces: qt-everywhere-opensource-src-4.6.3.zip

    QMAKE_CFLAGS_RELEASE = -O1 -Og -GL -MD

    configure -release -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-phonon-backend -no-multimedia -no-audio-backend -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -platform win32-msvc2008 -static -qt-sql-odbc -qt-sql-psql -qt-libjpeg -qt-zlib -qt-libpng -qt-gif

  31. Paolo
    September 3rd, 2010 at 05:47 | #31

    When I run the command “configure” I get “unable to detect platform from environment”.

    When I run the command “configure -platform win32-g++” or “configure -platform win32-msvc2008″ (I don’t know which one is the right one) I get this:

    “Creating qmake…
    execute: File or path is not found (mingw32-make)
    execute: File or path is not found (mingw32-make)
    Cleaning qmake failed, return code -1″

    both with the original qmake.conf:
    QMAKE_CFLAGS_RELEASE = -O2

    and with the modified one (as suggested in the article):
    QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer

    What’s wrong on my installation?

    Thanks in advance.
    Best regards.

    Paolo

    P.S.: I’ve installed QT SDK with QT Creator 1.3.0 based on Qt 4.6.0 with OS Windows XP and Windows Vista (same error)

  32. September 3rd, 2010 at 06:17 | #32

    @Paolo
    Were there any errors or other problems when performing step 3?

  33. Paolo
    September 3rd, 2010 at 06:44 | #33

    After adding the mingw32-make path in the PATH (environment variable) I could execute “configure” command. So that I’ve run:

    1) configure -platform win32-g++ –> result OK
    and
    2) configure -static –> result OK

    I must admit I did not executed the step 3 (is it mandatory?) as I cannot find “mingwvars.bat” under MinGW directory.

    At this point I tried to compile my project (which I was able to SUCCESSFULLY compile before the “configure” commands execution with “dynamic “linking method) but it does not work. I get the following error:

    “c:/qt/2009.05/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtXml
    collect2: ld returned 1 exit status
    mingw32-make[2]: *** [release\prj-server.exe] Error 1
    mingw32-make[1]: *** [release] Error 2
    mingw32-make: *** [sub-prj_server-pro-make_default-ordered] Error 2
    Exited with code 2.
    Error while building project prj
    When executing build step ‘Make’”

    I admit I’m really in trouble :-(

  34. September 3rd, 2010 at 07:13 | #34

    @Paolo
    @Paolo
    Step 3 is definitely mandatory, unless all the path information is entered in some other way.
    In general, an error with something like: “ld.exe: cannot find -lQtXml” means that the linker (ld.exe) can’t find a library (Qt’s XML library, which is probably qtxml.dll on Windows). This is usually because there’s no path telling it where to look.

    It would be nice if something a little more automatic and simple than ancient path variables were used by compilers, but it isn’t likely to happen any time soon.
    However, you can probably use Qt Creator (Nokia’s extremely excellent Qt IDE) to compile the project. It seems to take care of most of the location stuff for you (though note I’ve never compiled Qt itself with Qt Creator — just Qt-based projects).

  35. Paolo
    September 3rd, 2010 at 08:15 | #35

    @Charles N. Burns

    First of all thank you for help.

    I already use Qt Creator IDE to build my project, and that message was reported by it :-(

    About step 3, this is a problem, as really I’ve not tat file “mingwvars.bat” in my MinGW installation, which is not a stand-alone one, but the one installed by QT SDK installation inside its path: “C:\Programs\Qt\2009.05\mingw”

    Should I try to reinstall it stand-alone? From there http://sourceforge.net/projects/mingw/files/ ??

    Is it possible to get only the “mingwvars.bat” anywhere?

  36. September 3rd, 2010 at 08:43 | #36

    @Paolo
    I’ve had success with TDM GCC: http://tdm-gcc.tdragon.net/

  37. Paolo
    September 3rd, 2010 at 09:58 | #37

    I repeated all from the beginning by disinstalling everything and following the next steps according to the tutorial:

    step 1) installed QT SDK without MinGW
    installed TDM GCC
    (in the PATH there are: C:\Qt\2009.05\bin;C:\Qt\2009.05\qt\bin;C:\MinGW32\bin)

    step 2) in “win32-g++\qmake.conf” changed the line QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer

    step 3) executed “mingwvars.bat”

    step 4) executed the command
    “configure -release -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-g++ -static”

    step 5) attempted build with Qt Creator in release mode. It does not work again :-( (

    step 6) not executed (is this mandatory too?)

    Should I try the step 5 by command line using “mingw32-make”?
    If yes, could you tell me the syntax?

  38. September 3rd, 2010 at 11:10 | #38

    @Paolo
    I have never tried to build Qt Creator (I just use the binaries), but it is my understanding that the current version needs the new Qt 4.7 which has not been officially released yet. You can probably build it if you download the RC, but I’d just use the binaries. They work fine.

  39. Paolo
    September 3rd, 2010 at 12:01 | #39

    @Charles N. Burns

    I can try with binaries… but I need your help for it.
    Assuming that the project to build is named “alfa.pro” and located in “C:\dir\subdir\” what exactly should I write in the command line? Thank you again.

  40. September 3rd, 2010 at 12:04 | #40

    @Paolo
    Building a project in Qt Creator doesn’t need any command-line work. Just open the .pro file from within Qt Creator.

  41. Paolo
    September 3rd, 2010 at 12:16 | #41

    Hmm maybe I miss something… when you say you “use binaries” what do you mean exactly?
    I’m searching for another way (command line?) as I’ve already tried Qt Creator (inside) building without success.

  42. September 3rd, 2010 at 12:29 | #42

    @Paolo
    It may be best to ask on the Qt-Creator mailing list, as this may be getting somewhat OT. You can subscribe by sending an email whose subject is the word “subscribe” to qt-creator-subscribe@trolltech.com

  43. Gib Bogle
    September 17th, 2010 at 17:53 | #43

    Hi Charles,
    Have you tried the static build of Qt 4.6.3 on Windows with MinGW? I’m using mingw-4.4.0, and I get this compile error:

    In file included from qaxbase.cpp:45:
    qaxobject.h:44:30: error: ActiveQt/qaxbase.h: No such file or directory

    In fact there is no directory src/activeqt/container/activeqt in the 4.6.3 tree, although there is a file src/activeqt/container/qaxbase.h.

    Do you have any suggestions as to how I can get past this problem?

    Thanks
    Gib

    I tried to find an option to disable ActiveQT in the build, but it doesn’t seem to exist.

  44. Gib Bogle
    September 17th, 2010 at 17:59 | #44

    P.S. I should add that I’m using the opensource version of Qt.

  45. Gib Bogle
    September 18th, 2010 at 16:05 | #45

    I now find that the static build of 2010.04 with MinGW also gives an error (a different one).

    I wonder if anyone has tested building these releases static with MinGW.

  46. Gaurav Holey
    October 8th, 2010 at 05:40 | #46

    Dear Charles,

    Thank you very much for a great article.

    I have tried to compile the qt statically but success wont be in my favour. The configure step was run without any problem but the build process was giving me few nightmares because of loads of undefined references….

    I am using Qt Creator 2.0 and Qt 4.7.0 running on winxp SP-2.

    I am not able to compile and build the example projects of Qt since then.

    I had used following commands:

    configure -opensource -release -qt-libjpeg -qt-zlib -qt-libpng -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -mmx -sse -static -platform win32-g++

    mingw32-make

    every help would be appreciated.

    Regards,

    Gaurav Holey

  47. P. Berger
    November 24th, 2010 at 01:15 | #47

    Hi there, thank you very much for this good tutorial!

    But I have two questions left:
    Is there a way to compile in openssl support? Best thing would be to link it directly into the QT libs, but that always failed for me because of missing externals to user32.lib. Do you have any experience on how to do that?
    Second thing is mysql-support: Like openssl, building with mysql always fails with messages like this:

    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation. All rights reserved.

    link /LIBPATH:”c:\Qt\4.7.0\lib” /LIBPATH:”c:\Qt\4.7.0\plugins\sqldrivers
    ” /LIBPATH:”c:\Qt\4.7.0\lib” /NOLOGO /DEBUG /MANIFEST /MANIFESTFILE:”tmp\obj\deb
    ug_static\assistant.intermediate.manifest” /SUBSYSTEM:WINDOWS “/MANIFESTDEPENDEN
    CY:type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ publi
    cKeyToken=’6595b64144ccf1df’ language=’*’ processorArchitecture=’*'” /OUT:..\..\
    ..\..\bin\assistant.exe @C:\DOKUME~1\BliZZarD\LOKALE~1\Temp\nm54F.tmp
    QtSqld.lib(qsql_mysql.obj) : error LNK2019: unresolved external symbol _mysql_fe
    tch_field@4 referenced in function “public: bool __thiscall QMYSQLResultPrivate:
    :bindInValues(void)” (?bindInValues@QMYSQLResultPrivate@@QAE_NXZ)
    QtSqld.lib(qsql_mysql.obj) : error LNK2019: unresolved external symbol _mysql_nu
    m_fields@4 referenced in function “public: bool __thiscall QMYSQLResultPrivate::
    bindInValues(void)” (?bindInValues@QMYSQLResultPrivate@@QAE_NXZ)
    QtSqld.lib(qsql_mysql.obj) : error LNK2019: unresolved external symbol _mysql_st
    mt_result_metadata@4 referenced in function “public: bool __thiscall QMYSQLResul
    tPrivate::bindInValues(void)” (?bindInValues@QMYSQLResultPrivate@@QAE_NXZ)
    QtSqld.lib(qsql_mysql.obj) : error LNK2019: unresolved external symbol _mysql_st
    mt_close@4 referenced in function “protected: void __thiscall QMYSQLResult::clea
    nup(void)” (?cleanup@QMYSQLResult@@IAEXXZ)

    I used libs and includes from mysql-noinstall-5.1.53-win32.zip.
    thanks :)

  48. December 24th, 2010 at 01:52 | #48

    Hello
    When I compile Qt-based apps on WinXP with mingw32, I always add to pro file
    QMAKE_LFLAGS *= -static-libgcc
    this is to remove depends from libgcc_s_dw2-1.dll
    Also I use for debug builds only shared version of Qt, because link with static debug Qt libs take very long time, mingw32 doesn’t support increment link (

  49. cblog1
    March 29th, 2011 at 00:13 | #49

    Thanks for this article, it’s very good!!

  50. April 9th, 2011 at 16:15 | #50

    Nice tut! People who want to use the static (or plugin) MySQL support in Qt, also know as QMYSQL. Don’t forget to add “-L C:\MySQL\lib -I C:\MySQL\include” in your configure.

    Note: no spaces in the path to MySQL.

    My configure looks like this:
    configure -L E:\MySQL\lib -I E:\MySQL\include -release -nomake examples -nomake demos -no-exceptions -no-stl -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -static -qt-sql-mysql -platform win32-msvc2008
    [edited by moderator at user request 4/12/2011 10:22PM GMT]

Comment pages
1 2 920
  1. October 11th, 2009 at 20:20 | #1
  2. October 14th, 2009 at 22:54 | #2
  3. October 26th, 2009 at 06:39 | #3
  4. October 23rd, 2011 at 03:35 | #4