VS2010 using a statically compiled QT library

Source: Internet
Author: User

QT Development interface is very convenient, but the release of the program is not so convenient, you put the reference to the DLL together to publish, if you can statically compile it, when the release of only one EXE more convenient.

Although previously for convenience, the direct installation of the Qt-windows-opensource-5.0.2-msvc2010_32-x86-offline.exe, omitted to compile this step, but the official library is dynamically compiled, is in the form of Lib + DLL exist, So it's impossible to compile statically in my program.

       in order to be able to get the effect of static compilation, chose to compile their own source code, generate static library, the following is the whole process of compiling the static library.

       1, download qt source code, 5.0.2 qt-everywhere-opensource-src-5.0.2.zip 
        2, decompression to f:\qt-src-5.0.2 
       3, view the Readme file, It is mentioned that you need to download 3 installation tools  
   windows: 
  --------

Open a Windows SDK (7.0, 7.1 or later) command prompt. Ensure that the
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 choose the following address to download 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, CD to the source file directory, 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-ic U-opengl Desktop-qt-sql-sqlite-qt-zlib-qt-style-windowsvista-qt-libpng-qt-libjpeg-nomake Demos-nomake examples-no Make TESTS-MP

5, after the execution, directly run NMAKE (long wait)

6. Open VS2010, qt5--> Qt Options Add version

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

7. After the Qt project is created, QT-->QT project Settings, select the static library version: static5.0.2

8, first we run in debug mode, there will be the following link error
Qt5Cored.lib (qeventdispatcher_win.obj): Error lnk2019:unresolved external symbol[email protected]Referenced in function "Public:void __thiscall qeventdispatcherwin32private::d owsaasyncselect (int)" ([email protected]@@[email protected])

This link is easy to resolve, property page-->link-->input Additional Dependencies join Ws2_32.lib and then run

9, although the link error resolved, but the operation will still error

It will take some time to solve the problem, and the final solution will be provided directly 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 the debug mode static library name is followed by D, and the qwindows.lib is separate in one file and needs to be in the property page-->link-->general additional library  Directories join Lib directory,  
F:\qt-src-5.0.2\qtbase\plugins\platforms

10, the above Lib Plus, there is a key step, in the main function file to add the following two lines of code
#include <QtPlugin>
Q_import_plugin (Qwindowsintegrationplugin);

11, run the program, OK program can run up, check the following program, release EXE near 7M (default interface)

12, the above process is only to achieve the static compilation of the QT library, if you want your program independent of the compiler, you have to set the runtime library for/MT or/MTD


VS2010 using a statically compiled QT library

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.