Qt5.0编译指南(VisualStudio2010)

1 基础环境

->关于Qt源代码下载

Qt版本更替较快,一般在google里搜索Qt Download即可得到链接:https://qt-project.org/downloads ,可以在下面找到源代码下载链接.可以看到Qt的下载站点类似ftp站点:Qt目前最新的源代码包位于https://download.qt-project.org/official_releases/qt/5.0/5.0.2/single/,通过URL可以得到https://download.qt-project.org/提供了所有Qt相关的内容下载,下载Qt安装包和源代码包均可按图索骥.

采用git下载源代码编译可以参考链接:https://qt-project.org/wiki/Building_Qt_5_from_Git.

->关于Qt的Windows平台需求

https://qt-project.org/doc/qt-5.0/qtdoc/requirements-win.html中描述了Qt的Windows平台需求,其中

  • ANGLE为替代OpenGL的图形支持库,ICU为UNICODE及国际化支持库;
  • OpenSSL支持同样依赖于外部库.见https://qt-project.org/doc/qt-5.0/qtdoc/requirements.html
  • 编译需要Perl,创建QtWebKit依赖与Python及Ruby;
  • jom为替代nmake的构建工具,可以利用多核CPU来加速构建;
  • 使用Windows SDK 7.1编译时需要按照以下顺序完成SDK安装:
    • Install Visual Studio 2010
    • Install Windows SDK 7.1
    • Install Visual Studio 2010 SP1
    • Install Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1

ICU为UNICODE支持库,详细信息参见:http://site.icu-project.org/,其中ICU4C为C/C++支持库,ICU4J为Java支持库,简要介绍见:http://www.ibm.com/developerworks/cn/opensource/os-icu4c/,ftp下载站点为:http://download.icu-project.org/files/,针对MSVC10的32/64bit已编译包在可从http://download.icu-project.org/files/icu4c/51.1/下载.

ANGLE库可以从https://code.google.com/p/angleproject/获取,但是由于其在DirectX9上实现,必须要安装DirectX SDK.(https://www.microsoft.com/en-hk/download/details.aspx?id=6812).

其他工具下载链接:

Perl:http://www.activestate.com/activeperl/downloads

Python:http://www.python.org/download/

Rudy:http://rubyinstaller.org/

jom:https://qt-project.org/wiki/jom

2 Qt5.0模块分类

Qt5.0模块划分见https://qt-project.org/doc/qt-5.0/qtdoc/modules.html,可以根据所需模块选择性编译:

->基础模块

Qt CoreCore non-graphical classes used by other modules.提供给其他模块使用的核心非图形类对应于源代码目录Qtbase
Qt GUIBase classes for graphical user interface (GUI) components. Includes OpenGL.图形界面基础类,包含OpenGL 
Qt MultimediaClasses for audio, video, radio and camera functionality.音频、视频、无线电、相机功能类 
Qt NetworkClasses to make network programming easier and more portable.网络编程支持类源代码目录qtmultimedia
Qt QMLClasses for QML and JavaScript languages.QML及JavaScript支持类 
Qt QuickA declarative framework for building highly dynamic applications with custom user interfaces.使用自定义用户界面构建高动态应用程序的描述性框架 
Qt SQLClasses for database integration using SQL.基于SQL的数据库整合类 
Qt TestClasses for unit testing Qt applications and libraries.单元测试类 
Qt WebKitClasses for a WebKit2 based implementation and a new QML API. See also Qt WebKit Widgets in the add-on modules.源代码目录qtwebkit
Qt WebKit WidgetsWebKit1 and QWidget-based classes from Qt 4. 
Qt WidgetsClasses to extend Qt GUI with C++ widgets.扩展Qt GUI的C++组件类 

->附加组件

 

Active QtClasses for applications which use ActiveX and COM源代码目录qtactiveqt
Qt ConcurrentClasses for writing multi-threaded programs without using low-level threading primitives. 
Qt Graphical EffectsGraphical effects for use with Qt Quick 2. 
Qt Image FormatsPlugins for additional image formats: TIFF, MNG, TGA, WBMP. 
Qt OpenGLOpenGL support classes.

Note: Provided to ease porting from Qt 4.x. Please use the QOpenGL classes in QtGui for new code.

 
Qt Print SupportClasses to make printing easier and more portable. 
Qt DeclarativeQt Declarative is provided for Qt 4 compatibility. The documentation is available through the Qt 4.8 Qt Quickdocumentation.qtdeclarative
Qt ScriptClasses for making Qt applications scriptable. Provided for Qt 4.x compatibility. Please use the QJS* classes in the QtQmlmodule for new code. 
Qt Script ToolsAdditional components for applications that use Qt Script. 
Qt SVGClasses for displaying the contents of SVG files. 
Qt XML PatternsSupport for XPath, XQuery, XSLT and XML schema validation.qtxmlpatterns

 

->工具

Qt DesignerClasses for extending Qt Designer.
Qt HelpClasses for online help.
Qt UI ToolsClasses for UI tools.

3 配置选项

确保安装Perl之后,在源代码目录下运行

configure -help

可以得到Qt的配置选项.主要选项如下:

目录设置  
 -prefix <dir>指定编译结果目录,如果不指定编译结果将会出现在Qtbase下
库编译  
 -debug生成debug库
 -release生成release库
 -debug-and-release生成debug及release库
 -shared创建并使用动态Qt库
 -static创建并使用静态Qt库
模块编译  
 -make <part>编译(libs,tools,examples...)
 -nomake <part>不编译(libs,tools,examples...)
 -skip <module>构建时排除该模块
 -no-widgets禁止编译widgets模块
 -no-sql-<driver>禁止编译指定SQL驱动
 -no-opengl不支持opengl
 -opengl <api>

使能opengl指定API

desktop 桌面OpenGL

es1

es2

 -icu使用ICU库
 -no-icu不是用ICU
Windows支持  
 -no-vcproj不生成vc++.vcproj文件
 -vcproj只针对"win32-msvc.net",
 -no-openssl不编译openssl
...  

 

4 如何选择模块及配置

 源代码目录为: 

 Volume in drive D has no label.
 Volume Serial Number is 3245-ACDE

 Directory of D:\Qt\src

05/20/2013  09:48 PM    <DIR>          .
05/20/2013  09:48 PM    <DIR>          ..
05/20/2013  07:43 PM    <DIR>          .obj
04/09/2013  03:11 AM    <DIR>          gnuwin32
05/20/2013  07:58 PM    <DIR>          qtactiveqt
05/20/2013  07:57 PM    <DIR>          qtbase
04/09/2013  03:11 AM    <DIR>          qtdeclarative
04/09/2013  03:10 AM    <DIR>          qtdoc
04/09/2013  03:11 AM    <DIR>          qtgraphicaleffects
04/09/2013  03:11 AM    <DIR>          qtimageformats
04/09/2013  03:11 AM    <DIR>          qtjsbackend
04/09/2013  03:11 AM    <DIR>          qtmultimedia
04/09/2013  03:11 AM    <DIR>          qtquick1
05/20/2013  07:59 PM    <DIR>          qtscript
04/09/2013  03:11 AM    <DIR>          qtsvg
05/20/2013  08:06 PM    <DIR>          qttools
04/09/2013  03:10 AM    <DIR>          qttranslations
04/09/2013  03:11 AM    <DIR>          qtwebkit
04/09/2013  03:12 AM    <DIR>          qtwebkit-examples-and-demos
04/09/2013  03:11 AM    <DIR>          qtxmlpatterns
               0 File(s)              0 bytes
              20 Dir(s)  146,437,746,688 bytes free

 同样,可以查看源代码目录下的qtsdk.pro文件

addModule(qtbase)
addModule(qtsvg, qtbase)
addModule(qtxmlpatterns, qtbase)
addModule(qtjsbackend, qtbase)
addModule(qtdeclarative, qtjsbackend, qtsvg qtxmlpatterns)
addModule(qtmultimedia, qtbase, qtdeclarative)
addModule(qtactiveqt, qtbase)
addModule(qtwebkit, qtdeclarative, , WebKit.pro)
addModule(qttools, qtbase, qtdeclarative qtactiveqt qtwebkit)
addModule(qtwebkit-examples-and-demos, qtwebkit qttools)
addModule(qtimageformats, qtbase)
addModule(qtgraphicaleffects, qtdeclarative)
addModule(qtscript, qtbase)
addModule(qtquick1, qtscript, qtsvg qtxmlpatterns qtwebkit qttools)
addModule(qttranslations, qttools)
addModule(qtdoc, qtdeclarative)

 在Qt5.0中可以选择编译的模块为:

模块名所在目录描述
baseqtbase包含了Qt的基础类库,该类库必须编译
svgqtsvgClasses for displaying the contents of SVG files.显示SVG文件内容的类库
xmlpatternsqtxmlpatternsSupport for XPath, XQuery, XSLT and XML schema validation
jsbackendqtjsbackend构建依赖于Python
declarativeqtdeclarativeQt Declarative is provided for Qt 4 compatibility. The documentation is available through the Qt 4.8 Qt Quick documentation.
multimediaqtmultimediaClasses for audio, video, radio and camera functionality.
activeqtqtactiveqtClasses for applications which use ActiveX and COM
webkitqtwebkitClasses for a WebKit2 based implementation and a new QML API. See also Qt WebKit Widgets in the add-on modules.
imageformatsqtimageformatsPlugins for additional image formats: TIFF, MNG, TGA, WBMP.
graphicaleffectsqtgraphicaleffectsGraphical effects for use with Qt Quick 2.
scriptqtscriptClasses for making Qt applications scriptable. Provided for Qt 4.x compatibility. Please use the QJS* classes in the QtQml module for new code.
quick1qtquick1A declarative framework for building highly dynamic applications with custom user interfaces.
translationsqttranslationstr翻译功能
docqtdoc 
webkit-examples-and-demosqtwebkit-examples-and-demoswebkit的示例及演示
toolsqttools
Qt DesignerClasses for extending Qt Designer.
Qt HelpClasses for online help.
Qt UI ToolsClasses for UI tools.

 可以使用-skip modulename来跳过编译该模块.

  5 最小功能编译

 假设只是为了使用Qt的GUI库,也就是说,编译只依赖于base+tools模块,那么需要的工具为:

 ->Perl

 ->MSVC编译环境

 ->jom&wtee(wtee可以保持命令行输出并保存到文件,来给编译过程进行记录)

 可采用以下命令进行配置:

configure -prefix "D:\Qt\build" -release -opensource -nomake examples -no-opengl -no-openssl -no-openvg -no-angle -no-icu -no-vcproj -skip svg -skip xmlpatterns -skip jsbackend -skip declarative -skip multimedia -skip webkit -skip webkit-examples-and-demos -skip imageformats -skip quick1 -skip translations -skip doc -skip graphicaleffects  -mp -D _CRT_SECURE_NO_WARNINGS

 将编译结果存储在"D:\Qt\build"目录,使用release模式编译,不编译exampes.不是用opengl、openssl、openvg,不是用angle及icu,-no-vcproj来禁止产生vc工程文件(如果配置为参数vc工程文件,在实际配置中会报出很多找不到vcproj文件的警告),除了base和tools模块,其他全部跳过.使用-mp标志使能多处理器编译支持,使用"-D _CRT_SECURE_NO_WARNINGS"宏传递选项来禁止关于string操作的windows 不安全警报(报出的很多警告都是该原因).

 配置无误完成后.在qtbase\bin目录下会有qmake、moc等编译工具,用来编译其他Qt模块.然后使用如下命令进行编译:

jom -j<处理器数目> install 

在配置及编译时,假设将配置命令保存为cfg.bat,编译命令保存为install.bat,使用wtee记录中间的过程方式如下:

call cfg.bat |wtee cfg.log
call install.bat |wtee install.log

在I5-3320M 4核处理器,4G内存,64位Windows7操作系统上使用该配置编译耗时17分钟完成.在编译完成之后,build\bin目录下会有uitools编译完成,可以打开designer.exe来检查编译结果是否正常.这样编译出来的lib即可作为发布使用.

 注:Perl安装后自动设置环境变量,如果不确定,可以在命令行嵌入perl查看是否正常.

    :配置时最好从MSVC的命令行启动,configure会根据你启动的命令行判断你所使用的编译器版本及位数.

    :使用wtee及本文描述的.bat文件时,可以置于源代码根目录下

    :另外,如果使用-prefix指定编译结果路径,务必在编译时使用install目标,使用默认目标将会在qtbase\bin目录下创建build目录保存编译结果.

 6 配置引导

 ->我只是使用QtWidget来编写GUI程序,不需要Webkit和Quick

 如果是这样,安装就不会依赖与ANGLE和ICU库,同样Rudy及Python也不需要,也无需安装Direct SDK.你需要跳过webkit以及webkit-examples-and-demos,同时跳过jsbackend及quick1.并且采用-opengl desktop,以及 -no-angle标志.

 ->如何编译32bit和64bit的Qt

 对于MSVC来讲,编译两种Qt的不同支持仅仅在于启动的编译环境不同,其他配置均相同,当然你可能需要修改一下编译输出的路径(清除上次编译配置的命令为nmake confclean).

 ->关于debug与release

 配置时可以使用-release,-debug,-debug-and-release来使能相应的配置.

 ->静态库与动态库

 配置时,使用-shared得到动态库,-static得到静态库.

 ->多版本编译及共存的建议

 可以使用QtCreator来选择工具链,这样,可以在build目录下建立x86及x64两个目录,并在编译时分别指定对应目录,然后手动配置编译工具链.

 7 常规应用编译版本(不使用webkit及quick1)

 配置命令如下:

configure -prefix "D:\Qt\build\x64" -debug-and-release -opensource -opengl desktop -no-openssl -no-openvg -no-icu -no-vcproj -nomake examples -skip jsbackend -skip webkit -skip webkit-examples-and-demos -skip quick1 -skip declarative -skip multimedia -skip doc -skip graphicaleffects -mp -D _CRT_SECURE_NO_WARNINGS

注:关于模块间的依赖关系可见qtsdk.pro下面的addmodule.

 该配置在I5-3320M 4核处理器,4G内存,64位Windows7操作系统上使用该配置编译耗时30分钟完成.

 

转载于:https://www.cnblogs.com/liff-engineer/archive/2013/05/20/3088740.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值