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. Building Standalone Qt Application
Forum Update on Monday, May 27th 2025

Building Standalone Qt Application

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 7.1k 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.
  • N Offline
    N Offline
    ninadm
    wrote on last edited by
    #1

    Hi,

    I am very new to Qt and i am trying to build simple GUI using Qt, while i noticed that dynamic build is working fine for me but i need to package lot of required dependent modules with actual exe. so i decided to get the static app working but i am struggling a lot

    Steps:

    1. Built Qt 5.2.0 from source in both Static & Shared mode ( win 7 )
    2. Used MSVC-2012 compiler
    3. Compiled Qt-Creator from source using Shared (dynamically) built Qt
    4. http://qt-project.org/doc/qt-4.8/desktop-systray.html Used this project to see if i can compile and run application on Windows & Ubuntu - Dynamic build working fine
    5. Next step i tried is to build static version and its failing on Windows ( i managed to built it once but i am not able to reproduce the exact setup now )

    Environment:

    1. I have everything installed in different location c:\repo even MS Compiler and Qt and its working fine for Shared release
    2. I set following variables when i start Qt Creator

    @
    @echo off

    set REPO=C:\repo
    set QD_DYNAMIC=%REPO%\qt\5.2.0\release_x86_shared
    set QD=%REPO%\qt\5.2.0\release_x86_static
    set QMAKESPEC=win32-msvc2012
    set Platform=x86
    set VCINSTALLDIR=%REPO%\microsoft-tc\11.0.50727.1\VC
    set INCLUDE=%REPO%\microsoft-tc\11.0.50727.1\VC\INCLUDE;%REPO%\microsoft-sdk\8.0\include\shared;%REPO%\microsoft-sdk\8.0\include\um;%REPO%\microsoft-sdk\8.0\include\winrt
    set LIB=%REPO%\microsoft-tc\11.0.50727.1\VC\LIB;%REPO%\microsoft-sdk\8.0\lib\win8\um\x86
    set LIBPATH=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319;%SystemRoot%\Microsoft.NET\Framework\v3.5;%REPO%\microsoft-tc\11.0.50727.1\VC\LIB
    set Path=%REPO%\microsoft-tc\11.0.50727.1\Common7\IDE;%REPO%\microsoft-tc\11.0.50727.1\VC\BIN;%REPO%\microsoft-tc\11.0.50727.1\Common7\Tools;%SystemRoot%\Microsoft.NET\Framework\v4.0.30319;%SystemRoot%\Microsoft.NET\Framework\v3.5;%REPO%\microsoft-tc\11.0.50727.1\VC\VCPackages;%REPO%\microsoft-sdk\8.0\bin\x86;%REPO%\microsoft-sdk\8.0\Redist\D3D\x86;%Path%
    :: Adding Sharead bin path suggested here : http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW
    set PATH=%QD%\bin;%QD_DYNAMIC%\bin;%PATH%
    start bin\qtcreator.exe
    @

    1. Update the .pro file to create "Static" build

    @
    QT += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TEMPLATE = app
    TARGET = Window
    INCLUDEPATH += .

    CONFIG += static

    Adding below lines didnt help

    #static {

    CONFIG += static

    DEFINES += STATIC

    QTPLUGIN += qsvgicon qico qsvg qwindows

    message("Static Build")

    #}
    #QMAKE_CFLAGS_RELEASE += /MT
    #QMAKE_CXXFLAGS_RELEASE += /MT

    Input

    HEADERS += window.h
    SOURCES += main.cpp window.cpp
    @

    1. Run qmake
    2. Build ( Below is the o/p of build ) [ Apologies for pasting around 100 lines of o/p but i thought this might help to find whats wrong ]

    @
    set REPO=C:\repo
    set QD_DYNAMIC=%REPO%\qt\5.2.0\release_x86_shared
    set QD=%REPO%\qt\5.2.0\release_x86_static
    set QMAKESPEC=win32-msvc2012
    set Platform=x86
    set VCINSTALLDIR=%REPO%\microsoft-tc\11.0.50727.1\VC
    set INCLUDE=%REPO%\microsoft-tc\11.0.50727.1\VC\INCLUDE;%REPO%\microsoft-sdk\8.0\include\shared;%REPO%\microsoft-sdk\8.0\include\um;%REPO%\microsoft-sdk\8.0\include\winrt
    set LIB=%REPO%\microsoft-tc\11.0.50727.1\VC\LIB;%REPO%\microsoft-sdk\8.0\lib\win8\um\x86
    set LIBPATH=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319;%SystemRoot%\Microsoft.NET\Framework\v3.5;%REPO%\microsoft-tc\11.0.50727.1\VC\LIB
    set Path=%REPO%\microsoft-tc\11.0.50727.1\Common7\IDE;%REPO%\microsoft-tc\11.0.50727.1\VC\BIN;%REPO%\microsoft-tc\11.0.50727.1\Common7\Tools;%SystemRoot%\Microsoft.NET\Framework\v4.0.30319;%SystemRoot%\Microsoft.NET\Framework\v3.5;%REPO%\microsoft-tc\11.0.50727.1\VC\VCPackages;%REPO%\microsoft-sdk\8.0\bin\x86;%REPO%\microsoft-sdk\8.0\Redist\D3D\x86;%Path%
    :: Adding Sharead bin path suggested here : http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW
    set PATH=%QD%\bin;%QD_DYNAMIC%\bin;%PATH%
    start bin\qtcreator.exe
    @

    @
    17:27:06: Running steps for project Window...
    17:27:06: Configuration unchanged, skipping qmake step.
    17:27:06: Starting: "C:\repo\microsoft-tc\11.0.50727.1\VC\bin\nmake.exe"
    C:\repo\microsoft-tc\11.0.50727.1\VC\bin\nmake.exe -f Makefile.Release
    C:\Qt\build\rel_x86\bin\moc.exe -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -D_MSC_VER=1700 -D_WIN64 -I"..\Window" -I"....\build\rel_x86\include" -I"....\build\rel_x86\include\QtWidgets" -I"....\build\rel_x86\include\QtGui" -I"....\build\rel_x86\include\QtCore" -I"release" -I"." -I"....\build\rel_x86\mkspecs\win32-msvc2012" ..\Window\window.h -o release\moc_window.cpp
    cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MT -GR -W3 -w34100 -w34189 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I"..\Window" -I"....\build\rel_x86\include" -I"....\build\rel_x86\include\QtWidgets" -I"....\build\rel_x86\include\QtGui" -I"....\build\rel_x86\include\QtCore" -I"release" -I"." -I"....\build\rel_x86\mkspecs\win32-msvc2012" -Forelease\ @C:\Users\v140760\AppData\Local\Temp\nm5995.tmp
    main.cpp
    window.cpp
    Generating Code...
    cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MT -GR -W3 -w34100 -w34189 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I"..\Window" -I"....\build\rel_x86\include" -I"....\build\rel_x86\include\QtWidgets" -I"....\build\rel_x86\include\QtGui" -I"....\build\rel_x86\include\QtCore" -I"release" -I"." -I"....\build\rel_x86\mkspecs\win32-msvc2012" -Forelease\ @C:\Users\v140760\AppData\Local\Temp\nm76A7.tmp
    window_plugin_import.cpp
    cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MT -GR -W3 -w34100 -w34189 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I"..\Window" -I"....\build\rel_x86\include" -I"....\build\rel_x86\include\QtWidgets" -I"....\build\rel_x86\include\QtGui" -I"....\build\rel_x86\include\QtCore" -I"release" -I"." -I"....\build\rel_x86\mkspecs\win32-msvc2012" -Forelease\ @C:\Users\v140760\AppData\Local\Temp\nm7B59.tmp
    @

    1 Reply Last reply
    0
    • N Offline
      N Offline
      ninadm
      wrote on last edited by
      #2

      There is 6000 char limit in post hence splitting it in 2 posts , "..." == truncated o/p to fir in post

      @
      moc_window.cpp
      link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='' processorArchitecture=''" /MANIFEST /MANIFESTFILE:release\Window.exe.embed.manifest /OUT:release\Window.exe @C:\Users\v140760\AppData\Local\Temp\nm821E.tmp
      Qt5Widgets.lib(qapplication.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
      Qt5Widgets.lib(qsystemtrayicon.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Widgets.lib(qwidget.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      .
      .... *** TRUNCATED ***
      .
      Qt5Gui.lib(qicon.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Gui.lib(qguiapplication.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Gui.lib(qcursor.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      .
      .... *** TRUNCATED ***

      Qt5Core.lib(qarraydata.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Core.lib(qstring.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Core.lib(qpluginloader.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      .
      .... *** TRUNCATED ***
      .
      qwindows.lib(main.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      qwindows.lib(qwindowsintegration.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      qwindows.lib(qwindowsbackingstore.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5PlatformSupport.lib(qbasicfontdatabase.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5PlatformSupport.lib(Qt5PlatformSupport_pch.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5PlatformSupport.lib(qfontengine_ft.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Gui.lib(qplatformintegrationplugin.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Qt5Gui.lib(moc_qplatformnativeinterface.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      msvcprt.lib(MSVCP110.dll) : error LNK2005: "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc@std@@YAXXZ) already defined in libcpmt.lib(xthrow.obj)
      …
      MSVCRT.lib(MSVCR110.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
      …
      MSVCRT.lib(MSVCR110.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &,int)" (??0exception@std@@QAE@ABQBDH@Z) already defined in LIBCMT.lib(stdexcpt.obj)
      MSVCRT.lib(MSVCR110.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMT.lib(stdexcpt.obj)
      MSVCRT.lib(MSVCR110.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMT.lib(stdexcpt.obj)
      MSVCRT.lib(MSVCR110.dll) : error LNK2005: _strncpy_s already defined in LIBCMT.lib(strncpy_s.obj)
      …
      MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
      MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
      qtmain.lib(qtmain_win.obj) : error LNK2038: < SAME ERROR AS ABOVE >
      Creating library release\Window.lib and object release\Window.exp
      LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
      main.obj : error LNK2019: unresolved external symbol "struct QStaticPlugin const __cdecl qt_static_plugin_qsvgicon(void)" (?qt_static_plugin_qsvgicon@@YA?BUQStaticPlugin@@XZ) referenced in function "public: __thiscall StaticqsvgiconPluginInstance::StaticqsvgiconPluginInstance(void)" (??0StaticqsvgiconPluginInstance@@QAE@XZ)
      ….
      release\Window.exe : fatal error LNK1120: 4 unresolved externals
      NMAKE : fatal error U1077: 'C:\repo\microsoft-tc\11.0.50727.1\ia32-nt-4.0\VC\bin\link.EXE' : return code '0x460'
      Stop.
      NMAKE : fatal error U1077: 'C:\repo\microsoft-tc\11.0.50727.1\ia32-nt-4.0\VC\bin\nmake.exe' : return code '0x2'
      Stop.
      17:27:22: The process "C:\repo\microsoft-tc\11.0.50727.1\ia32-nt-4.0\VC\bin\nmake.exe" exited with code 2.
      Error while building/deploying project Window (kit: Qt_520_static)
      When executing step 'Make'
      17:27:22: Elapsed time: 00:16.
      @

      Any pointer, as there are so many errors i think something trivial is missing but i am not sure what is that ... any pointers?

      Thanks In Advance... - Ninad

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drhalftone
        wrote on last edited by
        #3

        I've been programming in Qt for about six years now, and I can honestly say that though it seems like static libraries are the way to go for redistributing your code, the difficulties that I encounter trying to compile Qt to static libraries outweigh their convenience. Since your new, you should read online about using Dependency Walker to identify the required DLLs and then just copy those DLLs to the same directory as the executable you want to distribute. Then use INNO setup to build an installer to actually do the redistribution.

        When you then move to Mac, you just run the macdeploy tool inside Qt's bin folder (same folder as qmake) to then build a *.app package you can just copy to a friend's Mac. The macdeploy tool will also copy over any libraries you might have installed using Mac Ports.

        On Ubuntu, the end user just needs to install the Qt libraries using Synaptic or other package manager. Then you can just copy the executable over, assuming its the same platform. I'm using an ARM based Ubuntu target. So I can't just copy the executable over to x86 platforms.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Here is a quick and dirty way of getting a dynamically-linked application to work: http://qt-project.org/wiki/Deploy_an_Application_on_Windows

          Once you have verified that it launches and works fine, you can get rid of unneeded files. (it's a boring task, but it's much easier than making static builds at the moment)

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            If I see things correctly

            @QMAKE_CFLAGS_RELEASE += /MT@

            You are trying to link your application statically, using also the static runtime but against a Qt version that was built against the dynamic runtime. So in short your can't mix both, everything must be linked to the same runtime

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              ninadm
              wrote on last edited by
              #6

              Ohh what a pointer :) i couldnt have thought of checking qmake.conf for statically built Qt ( somewhere in last couple of day i modified qmake.conf file with /Mt flags ... reverted the file and guess what... my app is working ...

              thanks all for your replies ... i could create backup plan if static thing didnt work :)

              [quote author="SGaist" date="1392885451"]Hi,

              If I see things correctly

              @QMAKE_CFLAGS_RELEASE += /MT@

              You are trying to link your application statically, using also the static runtime but against a Qt version that was built against the dynamic runtime. So in short your can't mix both, everything must be linked to the same runtime[/quote]

              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