Vs2010 uses a statically compiled QT Library (QT 5)

Source: Internet
Author: User

Qt 5 introduces a new writing method.

 

The QT development interface is very convenient, but it is not so convenient to publish a program. You only need to publish the referenced DLL together. If you can compile it statically, only one EXE is convenient during release.

Although qt-windows-opensource-5.0.2-msvc2010_32-x86-offline.exe is directly installed, the library provided by the official website does not support dynamic compilation because it exists in the form of LIB + DLL and cannot be statically compiled in my program.

In order to achieve the effect of static compilation, resolutely choose to compile the source code and generate a static library. The following is the entire process of static library compilation.

1. Download QT source code, 5.0.2 qt-everywhere-opensource-src-5.0.2.zip
2, extract to F: \ qt-src-5.0.2
3. view the README file. As mentioned, you need to download three Installation Tools.
Windows:
--------

Open a Windows SDK (7.0, 7.1 or later) command prompt. Ensure that
Following tools can be found in the path:
* Perl version 5.12 or later [http://www.activestate.com/activeperl/]
* Python version 2.7 or later [http://www.activestate.com/activepython/]
* Ruby version 1.9.3 or later [http://rubyinstaller.org/]

You can select the following address to download the file directly:
1. Perl 5.8 or later
X86 http://www.activestate.com/activeperl/downloads/thank-you? DL = http://downloads.activestate.com/ActivePerl/releases/5.16.3.1603/ActivePerl-5.16.3.1603-MSWin32-x86-296746.msi
Amd64 http://www.activestate.com/activeperl/downloads/thank-you? DL = http://downloads.activestate.com/ActivePerl/releases/5.16.3.1603/ActivePerl-5.16.3.1603-MSWin32-x64-296746.msi
2. Python 2.7 or later
X86 http://www.activestate.com/activepython/downloads/thank-you? DL = http://downloads.activestate.com/ActivePython/releases/2.7.2.5/ActivePython-2.7.2.5-win32-x86.msi
Amd64 http://www.activestate.com/activepython/downloads/thank-you? DL = http://downloads.activestate.com/ActivePython/releases/2.7.2.5/ActivePython-2.7.2.5-win64-x64.msi
3. Ruby
Amd64 http://rubyforge.org/frs/download.php/76806/rubyinstaller-2.0.0-p0-x64.exe

4. Enter open Visual Studio command prompt (2010), CD to the source file directory, and execute the following command

F: \ qt-src-5.0.1> Configure-Prefix F: \ QT-static-debug-and-release-static-platform win32-msvc2010-no-C ++ 11-no-ICU-OpenGL desktop-QT-SQL-SQLite-QT-zlib- qt-style-windowsvista-QT-libpng-QT-libjpeg-nomake demos-nomake examples-nomake tests-MP

5. Run nmake directly after execution (long waiting)

6. Open vs2010, qt5 --> QT options to add a version.

Static5.0.2 F: \ qt-src-5.0.2 \ qtbase

7. After creating the QT project, choose QT --> QT Project Settings and select static library version: static5.0.2.

8. First, we run in debug mode, and the following link error occurs:
Qt5cored. lib (qeventdispatcher_win.obj): Error lnk2019: unresolved external symbol [email protected] referenced in function "public: void _ thiscall qeventdispatcherwin32private: dowsaasyncselect (int) "([email protected] @ [email protected])

This link is easy to solve. The property page --> link --> input additional dependencies is added to ws2_32.lib and then runs

9. Although the Link error is fixed, an error will still be reported during running.

It takes some time to solve this problem. The final solution is provided below.

For programs that reference only the default three libraries of QT, the list of dependent Lib is as follows:
Imm32.lib
Winmm. Lib
Ws2_32.lib
Qtmaind. Lib
Qt5cored. Lib
Qt5guid. Lib
Qt5widgetsd. Lib
Opengl32.lib
Qt5platformsupportd. Lib
Qwindowsd. Lib

Note that the static library names in debug mode are followed by D. In addition, qwindows. Lib must be stored in a single file on the property page --> link --> General additional library directories to add the lib directory,
F: \ qt-src-5.0.2 \ qtbase \ plugins \ platforms

10. After adding the above Lib, there is another key step. Add the following two lines of code to the main function file:
# Include <qtplugin>
Q_import_plugin (qwindowsintegrationplugin );

11. Run the program. The OK program can run. Check the following program. The released version of EXE is close to 7 MB (default Interface)

12. The above process only implements static compiling of the QT library. If you want your program to be independent from the compiler, you must set the Runtime Library to/Mt or/MTD.

Vs2010 uses a statically compiled QT Library (QT 5)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.