Build Standalone Qt Application for Windows: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Updating Link into MSDN and parameters for mt.exe)
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
[[Category:Developing with Qt::General]]
[[Category:HowTo]]
[[Category:HowTo]]
 
{{LangSwitch}}
'''English''' [[Build_Standalone_Qt_Application_for_Windows_Bulgarian|Български]]
 
 
= Build Standalone Qt Application for Windows =


== Goal ==
== Goal ==
The goal of this article is to show how to build a standalone executable file of a Qt application for Microsoft Windows. This is an executable file that has no dependencies (aka does not require any dynamic linking to libraries). To create such a standalone version of a Qt application all required libraries should be embedded into the application using static linking. Please note that the size of the executable file will be larger.
The goal of this article is to show how to build a standalone executable file of a Qt application for Microsoft Windows. This is an executable file that has no dependencies (aka does not require any dynamic linking to libraries). To create such a standalone version of a Qt application all required libraries should be embedded into the application using static linking. Please note that the size of the executable file will be larger.


== Build a static version of Qt ==
== Build a static version of Qt ==
 
The first step is to build a static version of Qt. The commands that should be executed depend on the desired platform MinGW ('''win32-g++''') or Microsoft Visual Studio ('''win32-msvc''').
The first step is to build a static version of Qt. The commands that should be executed depend on the desired platform MinGW (*win32-g+''*) or Microsoft Visual Studio ('''win32-msvc''').


=== Using MinGW ===
=== Using MinGW ===
> configure -static -release -no-exceptions
> mingw32-make sub-src


<code>configure -static -release -no-exceptions
More information on static builds with mingw can be found [[How to build a static Qt version for Windows with gcc | here]]  
mingw32-make sub-src</code>
 
More information on static builds with mingw can be found [http://developer.qt.nokia.com/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc here] [developer.qt.nokia]


=== Using Microsoft Visual Studio ===
=== Using Microsoft Visual Studio ===
Make sure that Microsoft Visual Studio is installed. Start the Visual Studio 2008 Command Prompt. Otherwise you may get errors due to wrong or missing paths. Execute the following commands in the directory where Qt is installed (for example: C:\6.3\):


Make sure that Microsoft Visual Studio is installed. Start the Visual Studio 2008 Command Prompt. Otherwise you may get errors due to wrong or missing paths. Execute the following commands in the directory where Qt is installed (for example: C:.6.3:
> configure -static -release -platform win32-msvc
 
> nmake sub-src
<code>configure -static -release -platform win32-msvc
nmake sub-src</code>


Please note that reconfiguring and building Qt is a time consuming procedure. The duration may vary depending on the hardware of your computer.
Please note that reconfiguring and building Qt is a time consuming procedure. The duration may vary depending on the hardware of your computer.


== Build a static application ==
== Build a static application ==
Modify the .pro file of the project by adding an option for static linking.
Modify the .pro file of the project by adding an option for static linking.
<code>CONFIG''= static<code>
<tt>CONFIG+= static</tt>


=== Using MinGW ===
=== Using MinGW ===
To build the application run consecutively qmake and mingw32-make.


To build the application run consecutively qmake and mingw32-make.
> qmake Hello.pro
</code>qmake Hello.pro
> mingw32-make
mingw32-make <code>


=== Using Microsoft Tools ===
=== Using Microsoft Tools ===
To build the Qt project as a standalone executable file run qmake and nmake. After that you should execute mt.exe to embed a manifest inside the application to avoid error such as missing '''MSVCP90.dll''' when the application is started on other computers.
To build the Qt project as a standalone executable file run qmake and nmake. After that you should execute mt.exe to embed a manifest inside the application to avoid error such as missing '''MSVCP90.dll''' when the application is started on other computers.


</code>qmake Hello.pro
> qmake Hello.pro
nmake release
> nmake release
cd release
> cd release
mt.exe -manifest Hello.exe.manifest -outputresource: Hello.exe;1<code>
> mt.exe -manifest Hello.exe.manifest -outputresource:Hello.exe


Please note that the names of the manifest and the executable file depend on the name of your project.
Please note that the names of the manifest and the executable file depend on the name of your project.


== See also ==
== See also ==
 
* [[Building_a_static_Qt_for_Windows_using_MinGW]]
[http://www.qtcentre.org/wiki/index.php?title=Building_static_applications Building static applications]
* [https://msdn.microsoft.com/en-us/library/ms235591.aspx How to: Embed a Manifest Inside a C/C++ Application]
[http://www.qtcentre.org/wiki/index.php?title=Building_static_Qt_on_Windows Buildint static Qt on Windows]
* [[How to build a static Qt version for Windows with gcc]]
[http://msdn.microsoft.com/en-us/library/ms235591(v=VS.80).aspx How to: Embed a Manifest Inside a C/C++ Application ]
[http://developer.qt.nokia.com/wiki/How_to_build_a_static_Qt_version_for_Windows_with_gcc How to build a static Qt version for Windows with GCC]


== References ==
== References ==
 
* [http://www.anavi.org/article/140/ Standalone Qt Application for Microsoft Windows]
[http://www.anavi.org/article/140/ Standalone Qt Application for Microsoft Windows]

Latest revision as of 05:33, 13 September 2018

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Goal

The goal of this article is to show how to build a standalone executable file of a Qt application for Microsoft Windows. This is an executable file that has no dependencies (aka does not require any dynamic linking to libraries). To create such a standalone version of a Qt application all required libraries should be embedded into the application using static linking. Please note that the size of the executable file will be larger.

Build a static version of Qt

The first step is to build a static version of Qt. The commands that should be executed depend on the desired platform MinGW (win32-g++) or Microsoft Visual Studio (win32-msvc).

Using MinGW

> configure -static -release -no-exceptions
> mingw32-make sub-src

More information on static builds with mingw can be found here

Using Microsoft Visual Studio

Make sure that Microsoft Visual Studio is installed. Start the Visual Studio 2008 Command Prompt. Otherwise you may get errors due to wrong or missing paths. Execute the following commands in the directory where Qt is installed (for example: C:\6.3\):

> configure -static -release -platform win32-msvc
> nmake sub-src

Please note that reconfiguring and building Qt is a time consuming procedure. The duration may vary depending on the hardware of your computer.

Build a static application

Modify the .pro file of the project by adding an option for static linking. CONFIG+= static

Using MinGW

To build the application run consecutively qmake and mingw32-make.

> qmake Hello.pro
> mingw32-make

Using Microsoft Tools

To build the Qt project as a standalone executable file run qmake and nmake. After that you should execute mt.exe to embed a manifest inside the application to avoid error such as missing MSVCP90.dll when the application is started on other computers.

> qmake Hello.pro
> nmake release
> cd release
> mt.exe -manifest Hello.exe.manifest -outputresource:Hello.exe

Please note that the names of the manifest and the executable file depend on the name of your project.

See also

References