qt5开发——windows兼容xp的静态程序 qt5 development - static program which compatible xp on windows

in #qt7 years ago

近期做个windows的小工具程序需要使用到qt制作界面,程序要求兼容xp。鉴于工具很小,为免除qt过多的动态库,将程序编译为静态。下面对环境的搭建给出一些建议,如果有错误的地方欢迎帮忙纠正。ps:教程偏向于新手,环境为vs2013/vs2015、qt5.7.1、win8.1、使用qt creator编程

1 安装对应vs版本

请确保vs能够兼容xp开发。查看方法右击相应的项目,选择“属性”,在项目属性页中的“配置属性”下面的“常规”里面,如果“平台工具集”,可以由“Visual Studio 2013 (v120)”改成“Visual Studio 2013 - Windows XP (v120_xp)”,说明vs版本已经支持xp开发。如果vs版本(2013/2015)不支持,可联网完成更新补丁。

2.安装qt版本5.7.1

从官网下载对应的qt安装包。安装完成后,可能会因为缺少调试器报错无法构建项目。在工具->选项->构建和运行->构建套件->调试器(Debugger)一栏为空。缺少cbd调试器,现在的cbd已经被放入WDK中。可从微软上下载对应WDK。(ps:最新的WDK说是可以兼容所有系统,我自己只用了WDK8.1)重新启动qtcreator就可以选择x86或x64的调试器了。

3.获取对应版本的qt静态库

这里可以自己编译qt源码或者下载别人已经编译完成的版本。因为需要编译的时间太长,我从其他人的blog中下载了所需的静态包。在工具->选项->构建和运行->Qt Versions中添加你所需要的qmake.exe。例如我的就在下载的qt5-x86-static-release\bin中。如果显示qmlscene未安装,可在qt安装程序的目录下查找qmlscene.exe(在5.7\msvc2015\bin),复制到qt5-x86-static-release\bin中。之后在“构建套件”中添加一个新的或者将默认的套件中的“Qt 版本”修改为刚添加的qmake

3配置项目参数

这里有两种方法一种查找刚刚添加的静态库路径中的配置文件(mkspecs\common\msvc-desktop.conf)添加QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01 参数。另一种在项目的pro中添加
win32 {
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
DEFINES += ATL_XP_TARGETING
QMAKE_CFLAGS += /D_USING_V140_SDK71

QMAKE_CXXFLAGS += /D_USING_V140_SDK71_
LIBS += -L$$quote(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib)
INCLUDEPATH += $$quote(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include)
}
可以两个一起添加哦。(确保LIBS和INCLUDEPATH中的目录存在。如果项目提示Q5Widgetds.lib丢失,你尝试一下新建一个qt widgets application项目,选择自己刚设置的kit将默认的kit关闭,编译后进行测试。可用之后,再处理自己的项目。我就被这么折腾死过。)新建的项目在左侧导航栏的“项目”设置中需要将针对kit的“编辑构建配置”进行设置,如果使用的是release版本请切换成release,并将构建的目录放到工程目录的同一级目录下。

Google Translate:
Recently I need to use QT develop a program which is working on XP. Because it's simple, so I need to remove dynamic library and compile it into static application. There are some suggestions for the environment. If there are some mistakes, please correct them. ps: Tutorial is writted for the novice who use qt, the environment:vs2013 / vs2015, qt5.7.1, win8.1, qt

1 Install visual studio

Make sure you can use vs to develop programs that work on xp. Verification Method: Click "Project" -> "Properties" -> "Configuration Properties" -> "General" -> "Platform Tools".If you can change "Visual Studio 2013 (v120)" to "Visual Studio 2013 - Windows XP (V120_xp) ", you can use it develop. If you don't find it, please update it online.

2. Install qt 5.7.1

Download the installation package from the official website, you may not be able to build the project due to the lack of a debugger. Click Tools -> Options -> Build and Run -> Build Suite -> Debugger (Debugger), It lost CBD debugger. CBD has been placed in the WDK. You can download the WDK from Microsoft . (PS: the latest WDK that is compatible with all systems, I only use the WDK8.1) restart qtcreator,you can choose x86 or x64 of the debugger now.

  1. Get qt static library
    You can compile the QT source code by yourself or download static library which has been compiled. Because it need long time to compile it, I downloaded it from other's website. Then choose "Tools" -> "Options" -> "build and run" -> "Qt version" Add the qmake.exe which you need. For example, path like "qt5-x86-static-release\bin". If qmlscene is not installed, you can find it (at 5.7 \ msvc2015 \ bin) in the of installer directory of QT and copy it to "qt5-x86-static-release\bin". And then you can add a new setting in the "build package". Add your new "Qt version" to it.

3 Configure the project‘s parameter

There are two methods: 1.Find the configuration file (mkspecs \ common \ msvc-desktop.conf) in the static library path which you just added. Add the QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01 parameter. 2.Add into the .pro of the project
win32 {
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS.5.01
QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE, 5.01
DEFINES + = ATL_XP_TARGETING
QMAKE_CFLAGS + = / D_USING_V140_SDK71

QMAKE_CXXFLAGS + = / D_USING_V140_SDK71_
LIBS + = -L $$ quote (C: \ Program Files (x86) \ Microsoft SDKs \ Windows \ v7.1A \ Lib)
INCLUDEPATH + = $$ quote (C: \ Program Files (x86) \ Microsoft SDKs \ Windows \ v7.1A \ Include)
}
You can add two together, but please ensure that the contents of LIBS and INCLUDEPATH is exist. If the project prompts Q5Widgetds.lib lost when you build it, you can try to create a new qt widget application project. Select the toolkit which you just set it and turn off the default toolkit, compiled it successully. Then build your projects. I was beated by this problem).

Sort:  

Congratulations @ericvcloud! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!