[SOLVED] Qt 5.1.1. Win7. How to build an application statically



  • Hi,

    I want to build a simple application statically. I have Qt 5.1.1 and Win7.

    I need a simple step-by-step instruction. Because, I don't understand it http://qt-project.org/doc/qt-5.1/qtdoc/deployment-windows.html

    Please, give me links on step-by-step instructions. Please, help me!



  • Can I have two version of Qt on my computer: Building Qt Statically and Building Qt as a Shared Library?



  • I have questions about this instruction: http://qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.html

    [CODE]
    Building Qt Statically
    Before we can build our application we must make sure that Qt is built statically. To do this, go to a command prompt and type the following:
    cd C:\path\to\Qt
    configure -static <any other options you need>
    [/CODE]

    Is it right path?
    [CODE]
    C:\Qt\Qt5.1.1\5.1.1\mingw48_32\bin
    [/CODE]

    What should I write instead of <any other options you need>?
    Or I should write simple command configure -static. Is it right?


  • Lifetime Qt Champion

    Hi,

    No, configure can be found in Qt's sources.
    Yes, you can have as much version of Qt you need (and enough space on your hard drive)

    If you want several build of Qt, consider out of source building, otherwise you'll end up with several copies of the sources which are not needed.



  • Hi, thank you very much!

    What is "configure"?

    I tried to run it from "Administrator: Qt 5.1.1 for Desktop (MinGW 4.8 32 bit":
    [CODE]
    C:\Qt\Qt5.1.1\5.1.1\Src>configure -static
    'configure' is not recognized as an internal or external command,
    operable program or batch file.[/CODE]



  • I want to work with OpenGL. Do I need a flag -opengl desktop?



  • What does this mean?

    [CODE]
    WARNING: The DirectX SDK could not be detected:
    There is no Direct X SDK installed or the environment variable "DXSDK_DIR" is
    not set.
    Disabling the ANGLE backend.

    WARNING: Using OpenGL ES 2.0 without ANGLE.
    Specify -opengl desktop to use Open GL.
    The build will most likely fail.
    [/CODE]



  • Please, help me!!!



  • I ran mingw32-make confclean

    Please, say me what should I do?


  • Lifetime Qt Champion

    Please, have some patience.

    Unless you add -no-opengl, you'll get an OpenGL build. Without any precision on Windows, it will be an ANGLE build. If you add -opengl desktop you'll get a standard OpenGL build.

    Run configure and then call mingw32-make.

    I would advise using an out of source build, to avoid polluting the source tree with the files generated by the configure/compilation processes.



  • Thank you very much!

    I have now the default installation of Qt with course is here: C:\Qt\Qt5.1.1\5.1.1\Src\qtbase

    Should I to create another folder and copy to here of the course? For example: C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase

    Should I run this commands:
    configure -static -opengl desktop
    mingw32-make

    Should I intall DirectX SDK?

    Can I use DirectX from Qt?



  • I installed DirectX SDK from here: http://www.microsoft.com/en-us/download/confirmation.aspx?id=6812

    But the error was occured: http://img.pixs.ru/storage/6/5/1/107png_9391316_10038651.png

    [CODE]
    Examples installed to.......C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase\examples
    Tests installed to..........C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase\tests
    WARNING: Using static linking will disable the use of plugins.
    Make sure you compile ALL needed modules into the library.

    Generating Makefiles...

    Qt is now configured for building. Just run mingw32-make.
    To reconfigure, run mingw32-make confclean and configure.

    C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase>mingw32-make
    cd src/ && ( test -e Makefile || C:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/bin/qmake
    C:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src/src.pro -o Makefile ) && mingw32-make
    -f Makefile
    mingw32-make[1]: Entering directory 'c:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src'
    c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/bin/qmake.exe -o Makefile src.pro
    process_begin: CreateProcess(NULL, c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/bin/qmake.exe
    -o Makefile src.pro, ...) failed.
    make (e=2): The system cannot find the file specified.
    Makefile:569: recipe for target 'Makefile' failed
    mingw32-make[1]: *** [Makefile] Error 2
    mingw32-make[1]: Leaving directory 'c:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src'
    makefile:41: recipe for target 'sub-src-make_first' failed
    mingw32-make: *** [sub-src-make_first] Error 2
    [/CODE]



  • I added to PATH C:\Qt\Qt5.1.1_static\5.1.1\mingw48_32\bin

    But:

    [CODE]
    C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase>mingw32-make
    cd src/ && ( test -e Makefile || C:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/bin/qmake
    C:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src/src.pro -o Makefile ) && mingw32-make
    -f Makefile
    mingw32-make[1]: Entering directory 'c:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src'
    c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/bin/qmake.exe -o Makefile src.pro
    process_begin: CreateProcess(NULL, c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/bin/qmake.exe
    -o Makefile src.pro, ...) failed.
    make (e=2): The system cannot find the file specified.
    Makefile:569: recipe for target 'Makefile' failed
    mingw32-make[1]: *** [Makefile] Error 2
    mingw32-make[1]: Leaving directory 'c:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/src'
    makefile:41: recipe for target 'sub-src-make_first' failed
    mingw32-make: *** [sub-src-make_first] Error 2
    [/CODE]

    Please, help me!



  • I am building now from C:\Qt\Qt5.1.1\5.1.1\Src\qtbase

    I ran mingw32-make

    It is building now successfully

    Should I run mingw32-make install later?



  • I waited 2-3 hours. Now I see:

    [CODE]
    -lqwindowsd -lwinspool -lshlwapi -lQt5PlatformSupportd -lQt5Guid -lcomdlg32 -lol
    eaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lQt5Cored -lole32 -luuid -lws
    2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lz
    c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../..
    /i686-w64-mingw32/bin/ld.exe: final link failed: No space left on device
    collect2.exe: error: ld returned 1 exit status
    Makefile.Debug:79: recipe for target 'debug/tutorial2.exe' failed
    mingw32-make[4]: *** [debug/tutorial2.exe] Error 1
    mingw32-make[4]: Leaving directory 'c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/examples/qtes
    tlib/tutorial2'
    Makefile:34: recipe for target 'debug' failed
    mingw32-make[3]: *** [debug] Error 2
    mingw32-make[3]: Leaving directory 'c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/examples/qtes
    tlib/tutorial2'
    Makefile:67: recipe for target 'sub-tutorial2-make_first' failed
    mingw32-make[2]: *** [sub-tutorial2-make_first] Error 2
    mingw32-make[2]: Leaving directory 'c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/examples/qtes
    tlib'
    Makefile:278: recipe for target 'sub-qtestlib-make_first' failed
    mingw32-make[1]: *** [sub-qtestlib-make_first] Error 2
    mingw32-make[1]: Leaving directory 'c:/Qt/Qt5.1.1/5.1.1/Src/qtbase/examples'
    makefile:66: recipe for target 'sub-examples-make_first' failed
    mingw32-make: *** [sub-examples-make_first] Error 2[/CODE]


  • Lifetime Qt Champion

    Your hard drive is full



  • No, I have 648 MB now

    How to create a static application?



  • I ran: mingw32-make install It is installing


  • Lifetime Qt Champion

    "/i686-w64-mingw32/bin/ld.exe: final link failed: No space left on device" means your hard drive is full.

    You don't have everything built.

    To build your application statically, use your static version of Qt



  • Yes, I see. Thank you!

    I deleted Qt. I am trying to install it now. May I ignore this errors?
    http://img.pixs.ru/storage/6/0/1/108png_3122168_10047601.png
    http://i7.pixs.ru/storage/6/4/9/109png_4051130_10047649.png

    How can I solve it?


  • Lifetime Qt Champion

    Are you sure you have enough space on your hard drive ?



  • 15GB - free space



  • How many GBs are require?



  • How to prevent the building of examples?



  • It's bulding 8 hours. It taked more than 50 GB



  • I see addressbook every time.....

    bq. -DUNICODE -DQT_NO_EXCEPTIONS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NE
    EDS_QMAIN -I. -I'../../../../../include' -I'../../../../../include/QtWidgets' -I
    '../../../../../include/QtGui' -I'../../../../../include/QtCore' -I'.moc/debug_s
    tatic' -I'../../../../../mkspecs/win32-g++' -o .obj/debug_static/part1_plugin_im
    port.o part1_plugin_import.cpp
    C:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/bin/moc.exe -DUNICODE -DQT_NO_EXCEPTIONS -
    DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -D__GNUC__ -DWIN32 -
    I. -I'../../../../../include' -I'../../../../../include/QtWidgets' -I'../../../.
    ./../include/QtGui' -I'../../../../../include/QtCore' -I'.moc/debug_static' -I'.
    ./../../../../mkspecs/win32-g++' addressbook.h -o .moc/debug_static/moc_addressb
    ook.cpp
    g++ -c -pipe -fno-keep-inline-dllexport -g -fno-exceptions -frtti -Wall -Wextra
    -DUNICODE -DQT_NO_EXCEPTIONS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NE
    EDS_QMAIN -I. -I'../../../../../include' -I'../../../../../include/QtWidgets' -I
    '../../../../../include/QtGui' -I'../../../../../include/QtCore' -I'.moc/debug_s
    tatic' -I'../../../../../mkspecs/win32-g++' -o .obj/debug_static/moc_addressbook
    .o .moc/debug_static/moc_addressbook.cpp
    g++ -Wl,-subsystem,windows -o debug/part1.exe .obj/debug_static/addressbook.o .o
    bj/debug_static/main.o .obj/debug_static/part1_plugin_import.o .obj/debug_static
    /moc_addressbook.o -lmingw32 -lqtmaind -LC:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/
    lib -lQt5Widgetsd -LC:/Qt/Qt5.1.1_static/5.1.1/Src/qtbase/plugins/platforms -lqw
    indowsd -lwinspool -lshlwapi -lQt5PlatformSupportd -lQt5Guid -lcomdlg32 -loleaut
    32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lQt5Cored -lole32 -luuid -lws2_32
    -ladvapi32 -lshell32 -luser32 -lkernel32 -lz



  • When will it finished?


  • Lifetime Qt Champion

    Add "-nomake examples -nomake tests"



  • I typed this:

    configure -static -opengl desktop -nomake examples -nomake tests

    Output:

    bq. process_begin: CreateProcess(NULL, rm -f project.o option.o property.o main.o io
    utils.o proitems.o qmakeglobals.o qmakeparser.o qmakeevaluator.o qmakebuiltins.o
    makefile.o unixmake2.o unixmake.o mingw_make.o winmakefile.o projectgenerator.o
    meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o msvc_vcproj.o m
    svc_vcxproj.o msvc_nmake.o msvc_objectmodel.o msbuild_objectmodel.o gbuild.o ces
    dkhandler.o qtextcodec.o qutfcodec.o qstring.o qstringbuilder.o qtextstream.o qi
    odevice.o qmalloc.o qglobal.o qarraydata.o qbytearray.o qbytearraymatcher.o qdat
    astream.o qbuffer.o qlist.o qfiledevice.o qfile.o qfilesystementry.o qfilesystem
    engine.o qfsfileengine.o qfsfileengine_iterator.o qregexp.o qvector.o qbitarray.
    o qdir.o qdiriterator.o quuid.o qhash.o qfileinfo.o qdatetime.o qstringlist.o qa
    bstractfileengine.o qtemporaryfile.o qmap.o qmetatype.o qsettings.o qsystemerror
    .o qlibraryinfo.o qvariant.o qvsnprintf.o qlocale.o qlocale_tools.o qlinkedlist.
    o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o qlogging.o qfilesyste
    mengine_win.o qfilesystemiterator_win.o qfsfileengine_win.o qlocale_win.o qsetti
    ngs_win.o qsystemlibrary.o registry.o, ...) failed.
    make (e=2): The system cannot find the file specified.
    Makefile:155: recipe for target 'clean' failed
    mingw32-make: *** [clean] Error 2
    Cleaning qmake failed, return code 2
    C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase>



  • Now I am building of Qt on my old computer with XP. It was configured successfully.



  • It was building on my old computer with XP successfully! It took 1 or 1.5 hour.

    Please say me. Should I run this command: mingw32-make install



  • I compiled a simple project. But it was not build statically.



  • I ran this: mingw32-make install

    It is installing now. But I see:

    bq. can not be copied on top of itself



  • bq. xcopy /s /q /y /i C:\Qt\Qt5.1.1\5.1.1\Src\qtbase\doc\global C:\Qt\Qt5.1.1\5.1.1
    Src\qtbase\doc\global



  • I created the new folder with name C:/Qt5.1.1_static

    And copied to it the content of the folder C:\Qt\Qt5.1.1_static\5.1.1\Src\qtbase

    I ran this: cd C:/Qt5.1.1_static

    And this: configure -static -opengl desktop -nomake examples -nomake tests

    And I ran this: mingw32-make

    And this: mingw32-make install

    I open QtCreator -> and selected qmake.exe from C:/Qt5.1.1_static

    I created a simple Dialog Project (Release)

    But my Application-exe require the libgcc_s_dw2-1.dll

    Why? I want to ran my Application on another computer. Please help me! What should I do?



  • This is right for installing:

    configure -static -prefix "C:/Qt/Qt5.1.1_static" -opengl desktop -nomake examples -nomake tests

    But my Application-exe require the libgcc_s_dw2-1.dll How to build all dll's to one exe-file?



  • Need I to change mkspecs file?


  • Lifetime Qt Champion



  • Thank you for reply. I am helped here: http://www.prog.org.ru/topic_26164_0.html

    My "Step by Step" instruction how to build applications without libstdc++-6.dll, libgcc_s_dw2-1.dll, Qt5Core.dll, Qt5Gui.dll and so on.

    Tools:

    Version of Qt: Qt 5.2.0 for Windows 32-bit (MinGW 4.8, OpenGL, 689 MB)

    OS: Window 7

    • download and install Qt 5.2.0 for Windows 32-bit (MinGW 4.8, OpenGL, 689 MB) (check Source Components) from here http://qt-project.org/downloads

    • move to C:\Qt\Qt5.2.0\5.2.0\Src\qtbase\mkspecs\win32-g++ and open qmake.conf

    • find QMAKE_LFLAGS in qmake.conf and rewrite it:

    QMAKE_LFLAGS = -static -static-libgcc

    • open console Start -> All Programs -> Qt 5.2.0 -> 5.2.0 -> MinGW 4.8 (32-bit) -> Qt 5.2.0 for Desktop (MinGW 4.8 32 bit)

    cd c:\Qt\Qt5.2.0\5.2.0\Src\qtbase

    configure -static -prefix "C:\Qt\Qt5.2.0_static" -opengl desktop -nomake examples -nomake tests

    mingw32-make

    mingw32-make install

    • run QtCreator

    • in menu Tools -> Options...

    • Build & Run -> Qt Versions -> click "Add..." button -> select "C:\Qt\Qt5.2.0_static\bin\qmake.exe" -> click "Apply" button

    • go to "Kits" tab -> click "Add" button

    • write in the field "Name": Desktop Qt 5.2.0 Static MinGW 32 bit

    • select in "Qt version": static Qt virsion

    • click Ok

    • create a test project, for this:

    • in menu "File" -> "New File or Project" -> "Applications" -> "Qt Widgets Application" -> click "Choose" button

    • enter the "Name": Hello_Static_Qt -> enter the "Create in": D:\QtProjects -> click "Next" -> select "Desktop Qt 5.2.0 Static MinGW 32 bit" -> click "Next" -> click "Next" -> click "Finish"

    • click "Projects" in the right panel

    • click "Desktop Qt 5.2.0 Static MinGW 32 bit" on the top

    • select "Edit build configuration": Release

    • in the "Build Steps" in "qmake" expend "Details"

    • select "qmake build configuration": Release

    • enter "Additional arguments": "CONFIG += release" (in double quotes)

    • in "Menu" -> click "Build" -> "Build Project 'Hello_static_Qt'"

    • go to "D:\QtProjects\build-Hello_Static_Qt-Desktop_Qt_5_2_0_Static_MinGW_32bit-Release\release"

    • run your static application: Hello_Static_Qt.exe


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.