The latest Qt version 5.12.2 complete Win10 environment static compilation process in the installation and deployment (VS2017)

First, why should compile statically

用QtCreator编译程序时,使用的是动态编译。编译好的程序在运行时需要另外加上相应的Qt库文件,一大堆dll文件。如果想将生成的程序连同所需要的库一起完整地打包成一个可执行程序,那就需要使用静态编译。Qt官方不提供静态编译好的安装包,所以需要我们在自己的电脑上静态编译。而且exe文件会比动态编译的要小上很多。

Second, the source download

Source Download

Open URL selection generally opt for the latest version, according to a long-term technical support QT official Qt5.12 this edition, about five years look like the stability is relatively high, it is recommended to choose this version of the source code to compile. I compile time is Qt5.12.2, MD I had just the day before yesterday to compile good today just like New Qt5.12.3. Injury can not afford ah.

Third, install the compilation tools

Installation compilation tools are:

  1. This powerful tool pythone no friends, it has the feeling of doing
  2. Ruby download page has suggested, it is generally recommended to download the official stable version
  3. Download the latest version of Perl, nothing wrong with the old iron.

In general these three tools you can download, remember to set the environment variable, of course, you want to compile MSVC version installed Visual Studio2017, and install it.

Fourth, select the build environment

  这次我选择编译x86的静态库,原因很简单。64位的系统可以运行32位的程序,但是反之则不可以,所以选择编译环境位x86

Fifth, the compiler configuration parameters

Open Source location (qtbase \ mkspecs \ common \ msvc-desktop.conf) to find the location shown in Figure file and save changes:

Sixth, start compiling

  1. First open a command prompt tool to switch to the source location

  1. After the handover complete the following command input (recommended copy and paste):
configure.bat -static -prefix "D:\Qt\msvc2017_static" -confirm-license -opensource  -debug-and-release -platform win32-msvc  -nomake examples -nomake tests  -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -mp
 configure.bat 
 -static //指明是静态编译
 -prefix "D:\Qt\msvc2017_static" //指明安装的目录
 -confirm-license -opensource  //指明是开源版本的qt
 -debug-and-release //指明需要debug版和release版,可以单独选择release版
 -platform win32-msvc  //指明使用msvc编译
 -nomake examples -nomake tests  //不编译样例
 -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg //可选插件
 -opengl desktop 
 -mp //多核编译
  1. make
    prompt tool in the command:
    nmake
    at this time began to compile the source code, compile duration varies according to the configuration of the computer, my computer I7 7500U Inter240GSSD, from work about 9:00 o'clock start building, at 6 o'clock in the afternoon when the work does not compile End, etc. work the next morning after the discovery has been compiled over, I do not know specifically how long. Optimism over 12+ hours.

  2. nmake install
    After installation tool at the command prompt:
    nmake install
    at this time to compile the source code numbers to start the installation, this long probably about two hours to install it. After the installation is complete you can use.

Seven, started

源码编译安装完成之后,需要安装Qt Creator工具来使用我们刚刚编译好的静态QT。首先下载 [QtCreator](http://download.qt.io/official_releases/qtcreator/)

Still choose to download and install the latest version. After the installation is complete, open development tools we need to configure it to use.

** Note: In There must be days to write "win32-msvs". Otherwise the compiler will report compiled object type error **

After configuring the above you can begin assured compile your own program. Test it blank program in release mode is probably about 11M, it is still quite large, the advantage is to have to worry about missing DLL files being given.

Eight Notes

  1. When you add Qt Versions may report "qmlscene not installed", a yellow exclamation point. This is you only need to install the official Qt dynamically compiled installer copies the appropriate directory of "qmlscene.exe" We have just compiled and installed to Re-added to ok directory.

  2. Qt Versions bit when you download other people compiled their own static library or libraries compiled moved up one position when an error "qt is not installed correctly, use make install to install." Do not be afraid fact, without recompiling the installation, just in Create a new text document "qt.txt" directory, then enter

[Paths]
Prefix=D:/qt/static

** Note: Select "ANSI" Once you have entered when you save, save as, when selectively prompted to select "ANSI" type can be. Finally qt.txt changed qt.conf. **

Nine, at the end

做好上述8个步骤之后我们的静态环境就彻底搭建好了,然后就欢乐的码代码吧。

附上自己编译的静态库和编译工具 :链接:https://pan.baidu.com/s/1E3Y40FCmzQQMz_doZ0OYcQ  提取码:fme4

Guess you like

Origin www.cnblogs.com/wenlibest/p/11419842.html