讨论下Windows平台如何编译Qt5?

老邓 2011-11-27 10:29:10
加精
Qt5的编译官方有一篇wiki:http://developer.qt.nokia.com/wiki/Building_Qt_5_from_Git
简要的总结下我的体会,欢迎补充完善、批评指正。

1.First clone the top-level qt5 git repository:
git clone git://gitorious.org/qt/qt5.git qt5

这一行不用说了,自然是将Qt5的代码克隆。不过,如果你只是初次克隆Qt5的代码,会很惊讶:为何克隆后的代码只有十几MB?
原来,Qt5已经实现了Qt的模块化,详见:http://labs.qt.nokia.com/2011/05/12/qt-modules-maturity-level-the-list/
所以可以在克隆得到的Qt5源码根目录下看到:.gitmodules 文件,其内容部分摘录如下:
[submodule "qtbase"]
path = qtbase
url = git://gitorious.org/qt/qtbase.git
[submodule "qtsvg"]
path = qtsvg
url = git://gitorious.org/qt/qtsvg.git
[submodule "qtdeclarative"]
path = qtdeclarative
url = git://gitorious.org/qt/qtdeclarative.git
...

这时,有Git基础的朋友一定会想到:
git submodule init
git submodule update

不过,请不要这样做!

2. Following the README file we initialize the repository. This clones the various sub-modules of Qt5:
./init-repository

这是一个perl脚本。如果是在msys-git下,会发现Perl的版本不够。
我们需要安装一个Windows版本的Perl:http://www.activestate.com/activeperl/downloads
安装好以后,Perl就添加到PATH环境变量中去了。
在MSVC的控制台下执行:
perl init-repository --help

注意,不是直接执行init-repository,要用perl来执行它。看看帮助:大致了解下有哪些功能。

3. 注意它的三个小提示:
Hint1: If you’re going to contribute to Qt 5, you’ll need to pass the —codereview-username <Jira/Gerrit username> option to set up a “gerrit” remote for all the sub-modules.
Hint2: If you’re having problems downloading the webkit repository (which is quite big), you can pass —no-webkit.
Hint3: If you’re behind a firewall, pass —http


4. 我的方法:
perl init-repository -f --codereview-username loaden

这样就可以实现子模块的批处理了。特别要注意的是:在处理这些子模块时,其实是git clone了这些子模块,以致于他们可以独立使用。在qt5\qtbase目录下可以找到.git目录。
这与git submodule update的结果是不一样的!!
同时我使用了codereview的用户名,是为了可以创建一个名为gerrit的远程仓库,可以将贡献的代码推送进去,类似:
git push gerrit HEAD:refs/for/master


5. 源码下载是非常慢的,因为QtWebkit达到了1.7GB。源码下载完成后,进入Qt5源码目录,配置环境变量:
set PATH=%CD%\qtbase\bin;%PATH%

之后echo看一下结果是否正确:
echo %PATH%


6. 建议直接在Qt5的源码目录下执行配置!
configure -confirm-license -opensource -release -shared -platform win32-msvc2010 -fast -no-stl -no-qt3support -nomake examples -nomake demos -nomake tests


7. 编译全部模块,直接执行nmake就可以了。如果只编译一个模块,可以这样:
nmake module-qtbase

双击打开Qt5目录下的Makefile文件,可以看到有这些模块:
SUBTARGETS    =  \
module-qtbase \
module-qtsvg \
module-qtphonon \
module-qtxmlpatterns \
module-qtdeclarative \
module-qttools \
module-qttranslations \
module-qtdoc \
module-qlalr \
module-qtqa \
module-qtlocation \
module-qtactiveqt \
module-qtsensors \
module-qtsystems \
module-qtmultimedia \
module-qtfeedback \
module-qtquick3d \
module-qtdocgallery \
module-qtpim \
module-qtconnectivity \
module-qtwayland \
module-qtjsondb \
sub-qtwebkit-pri \
module-qtwebkit-examples-and-demos

欢迎交流!
...全文
14628 84 打赏 收藏 转发到动态 举报
写回复
用AI写文章
84 条回复
切换为时间正序
请发表友善的回复…
发表回复
derek_chencai 2013-02-18
  • 打赏
  • 举报
回复
我用的QT5.0.1+MINGW4.7,安裝之后build了一個空的工程,編譯不會出錯。執行時需要在執行文件下加入動態庫文件(我目前加入的是bin文件夾下的文件),但是打包出去到別的(沒安裝過QT)電腦上運行卻要出錯,我猜是不是運行還要調用一些安裝出來的文件,這些又是哪些文件呢?請版主大人和各位大神幫忙指點指點!!!
aileenyuxiao 2013-01-16
  • 打赏
  • 举报
回复
为什么我用vs2010编译,出现了下面的错误,是不是还需要修改什么啊 moc_qmlprofilerapplication.cpp moc_commandlistener.cpp moc_qmlprofilerdata.cpp moc_qmlprofilerclient.cpp moc_qqmldebugclient.cpp moc_qpacketprotocol.cpp link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:CONSOLE " /MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' versio n='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture ='*'" /MANIFEST /MANIFESTFILE:E:\qt\qt-everywhere-opensource-src-5.0.0\qtbase\bi n\qmlprofiler.exe.embed.manifest /OUT:E:\qt\qt-everywhere-opensource-src-5.0.0\q tbase\bin\qmlprofiler.exe @C:\Users\YAODAN~1.ZHA\AppData\Local\Temp\nm430F.tmp LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT. lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSV CR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MS VCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRT.lib(M SVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.l ib(MSVCR100.dll) LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminat e@@YAXXZ) already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(rand_s.obj) : error LNK2005: _rand_s already defined in MSVCRT.lib(MS VCR100.dll) LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCR T.lib(MSVCR100.dll) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib( cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib( cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib( cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib( cinitexe.obj) LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRT .lib(MSVCR100.dll) LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRT.lib(MS VCR100.dll) LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MS VCR100.dll) LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVC R100.dll) LIBCMT.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRT. lib(crtexe.obj) LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVC RT.lib(MSVCR100.dll) Creating library E:\qt\qt-everywhere-opensource-src-5.0.0\qtbase\bin\qmlprofi ler.lib and object E:\qt\qt-everywhere-opensource-src-5.0.0\qtbase\bin\qmlprofil er.exp LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; us e /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; us e /NODEFAULTLIB:library E:\qt\qt-everywhere-opensource-src-5.0.0\qtbase\bin\qmlprofiler.exe : fatal erro r LNK1169: one or more multiply defined symbols found NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0 \VC\BIN\link.EXE"' : return code '0x491' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0 \VC\BIN\nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: 'cd' : return code '0x2' Stop. NMAKE : fatal error U1077: 'cd' : return code '0x2' Stop. NMAKE : fatal error U1077: 'cd' : return code '0x2' Stop.
  • 打赏
  • 举报
回复
和你同姓,而且也在用Qt5,顶一下!Qt5和Qt4兼容性还不错,下载了正式版,用 VS2010Express + CDB
GoodQt 2012-12-21
  • 打赏
  • 举报
回复
引用 80 楼 bygreen 的回复:
哪个编译过了5.0的正式版的么,我怎么第一步就过不去,根本找不到qtbase下的configure.exe的呢????
注释掉qtbase\configure.bat中的一行文字 (用记事本打开会不能换行 最好用其他的编辑软件打开) 将
if not exist %QTSRC%\.gitignore goto sconf
前面加上::注释掉 就是修改为
::if not exist %QTSRC%\.gitignore goto sconf
bygreencn 2012-12-20
  • 打赏
  • 举报
回复
哪个编译过了5.0的正式版的么,我怎么第一步就过不去,根本找不到qtbase下的configure.exe的呢????
GoodQt 2012-10-13
  • 打赏
  • 举报
回复
[Quote=引用 55 楼 的回复:]
编译过程中出现Project Error: To build QtWebKit with Qt 5 you need ICU.这是什么错误呢?ICU是International Components for Unicode?如何使用?不知道有没有碰到这样问题的。
[/Quote]
我已经编译成功了(准确的说已经开始编译WebKit了,还没完)
经验:
1.下载ICU的MSVC版(视你的编译器而定)(我下载的是已经编译好的,愿意自己编译应该也行)
2.复制 ICU目录/lib下文件到 Qt目录/qtbase/lib目录
3.复制 ICU目录/include下文件到 Qt目录/qtbase/include目录
4.(可选,因为我想这个是运行时需要,编译可以忽视,我就没复制) 复制 ICU目录/bin目录下文件 到 Qt目录/bin目录
5.(重要)重新执行 configure -icu 否则 还是会报错
6. 执行 nmake
fox000002 2012-09-03
  • 打赏
  • 举报
回复
[Quote=引用 75 楼 的回复:]

为什么我configure都过不去?
error message: Cannot chdir to C:\qt5\configure: No such file or directory at c:\qt5\configure line 82
环境:windows 7, vc2008, perl 5.6.1,
命令: configure -prefix %CD%\qtbase -opens……
[/Quote]

perl 版本太低,脚本解析有问题
fox000002 2012-09-03
  • 打赏
  • 举报
回复
[Quote=引用 75 楼 的回复:]

为什么我configure都过不去?
error message: Cannot chdir to C:\qt5\configure: No such file or directory at c:\qt5\configure line 82
环境:windows 7, vc2008, perl 5.6.1,
命令: configure -prefix %CD%\qtbase -opens……
[/Quote]

perl 版本太低,脚本解析有问题
Dora112 2012-06-01
  • 打赏
  • 举报
回复
加我工作Q吧,2602240703,可以交流下
barcode128 2012-05-31
  • 打赏
  • 举报
回复
为什么我configure都过不去?
error message: Cannot chdir to C:\qt5\configure: No such file or directory at c:\qt5\configure line 82
环境:windows 7, vc2008, perl 5.6.1,
命令: configure -prefix %CD%\qtbase -opensource -nomake tests
fq15973135977 2012-04-22
  • 打赏
  • 举报
回复
看来我落武了,最近还在使用QT4.8中~~
江北百晓生 2012-04-22
  • 打赏
  • 举报
回复
多次编译,最终都败在了v8.h目录什么的不对,而且Qt Webkit是暂时禁止在Windows上编译的。
老邓 2012-04-13
  • 打赏
  • 举报
回复
嗯,天天呆着没事的时候,就编译master分支玩儿。
wandaoyongshi 2012-04-10
  • 打赏
  • 举报
回复
qt5 alpha下载完成,马上开始编译 哇卡卡

http://developers.solidot.org/developers/12/04/09/1117246.shtml
jinling4388 2012-04-09
  • 打赏
  • 举报
回复
收藏!!!!!
老邓 2012-04-07
  • 打赏
  • 举报
回复
[Quote=引用 67 楼 的回复:]

刚才使用Qt5编译QtCreator,发现竟然不再依赖QWebkit了。
奇怪!
[/Quote]
邮件列表中的回复。
请无视我蹩脚的英语。
On 4 Apr 2012, at 10:53, ext Loaden wrote:

> Hi, All!
> I am use currently master of Qt5, and build QtCreator master branch.
> I do not compile QWebKit, But I can use Help plugin as well.
> The mean we not need QWebKit now for QtCreator now?

QtWebKit was never a hard requirement for Qt Creator, it uses QTextBrowser as a fallback. This has quite some limitations regarding supported html, css, js, so it *might* be that it just fails with our documentation in that regard.

Br, Eike

> But there has a issue: The qch help can't show any picture, just see the attanchments.
> Or, please have a look: http://loaden.googlecode.com/files/1.PNG
> Any comments are welcome.
>
> --
> Regards
> Loaden
>
> <1.PNG>_______________________________________________
> Qt-creator mailing list
> Qt-creator@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator
老邓 2012-03-17
  • 打赏
  • 举报
回复
貌似官方现在也没搞定QWebkit的编译。
最近要出的Qt5 alpha中应该不包含qwebkit这个模块。
老邓 2012-03-17
  • 打赏
  • 举报
回复
刚才使用Qt5编译QtCreator,发现竟然不再依赖QWebkit了。
奇怪!
hemiya 2012-03-17
  • 打赏
  • 举报
回复
我还是老实用4.7版吧。
Vincent_Song 2012-03-13
  • 打赏
  • 举报
回复
已经QT5了。。。。
加载更多回复(49)

16,173

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧