How To Compile Qt with Visual Studio
2017-01-30 21:18
453 查看
How To Compile Qt with Visual Studio
FEBRUARY 1, 2011This post is a step-by-step guide on how to compile Qt 4.x.x with MSVC 2010.
Although we use Qt 4.7.1 as an example (for historical reasons), you can also find suggestions on building newer versions of Qt by MSVC 2012 and even by Intel Compiler for both platforms x86 and x64. All kudos go to numerous contributors, who spend their time to do all the tweaking and testing (see updates below).
In particular there are instructions on how to build Qt 5 for x64 platform contributed by Vincenzo Mercuri.
Updates
December 21, 2012. Vincenzo Mercuri shared instructions for building Qt 5.0.0 in x64 configuration.
December 19, 2012. Vincenzo Mercuri informed that he have compiled Qt 4.8.4-x64 by the guide. Also he shared his instructions for building Qt with Intel C++ Compiler into static library.
November 4, 2012: As reported by Mike Pelton, whatnick and Borislav Stanimirov, 32 & 64bit versions of Qt 4.8.3 have been successfully compiled by this guide, by both Visual Studio 2010 & 2012. Be aware that Qt might not be adjusted yet for Windows 8 (as reported here).
June 4, 2012: As reported by Wenqing, Qt 4.8.2 has been successfully compiled by this guide.
April 5, 2012: As reported by Snouty, 32bit version of Qt 4.8.1 has been successfully compiled by this guide.
December 20, 2011: As reported by Evon, 64bit version of Qt 4.8.0 has been successfully compiled by this guide. To do 64bit compilation, please use
Visual Studio x64 Win64 Command Prompt (2010)in step 8. Also please use
jom 1.06and don’t forget to install Service Pack 1 for Visual Studio.
September 16, 2011: Qt 4.7.4 has been successfully compiled by this guide.
August 14, 2011: In order to build Qt for 64 bits just use
Visual Studio x64 Win64 Command Prompt (2010)in step 8. Also install Service Pack 1 for Visual Studio 2010 beforehand – it fixes few bugs related to x64 compilation.
July 18 2011: Qt 4.7.3 and Qt 4.8 (beta) has been successfully compiled by this guide. Just replace version number where applicable.
Build instructions
Visual C++ 2010 contains all necessary SDKs for Qt compilation. However if you plan to use Qt with Phonon you need to install DirectX SDK first.
Install Perl if you are going to compile Qt >= 4.8.0
Download and extract Qt 4.7.1 Source Code. (Qt 4.8.0 or Latest snapshot).
Copy contents of the folder
qt-everywhere-opensource-src-4.7.1to the directory where you intend to install Qt. In our case this is
C:\Qt\4.7.1.
Set up environmental variables
QTDIR=C:\Qt\4.7.1 QMAKESPEC=win32-msvc2010
Update
PATHvariable to include
%QTDIR%\bin
Download the latest version of jom.
Extract jom files to
C:\Qt\jomfolder
Start Visual Studio 2010 Command Prompt:
Start > Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt.
Run following commands in it (every line is a different command: type it then press
Enter):
cd c:\Qt\4.7.1 configure -debug-and-release -opensource -platform win32-msvc2010 ..\jom\jom.exe -j N
Where
Nis number of CPU cores you want to utilize for Qt compilation. Larger is better.
Download and install Qt Visual Studio Add-in.
Run Visual Studio 2010. Integrate just compiled Qt to IDE using menu
Qt > Qt Options > Qt Versions > Add
Usually compilation takes about 10 hours, but thanks to jom and Intel SSD drive it took only 2 hours 40 minutes on my machine (Windows 7, 64bits)
Remarks
* Jom isnmakereplacement for Qt compilation on multi-core CPU. Its parameter
-j Nallows to setup number of parallel processes for compilation. Number of physical CPU cores is a good choice for
N.
** Do not forget to use
/dswitch if you want to change drive in command prompt, e.g:
cd /d d:. Usual
cd d:does not work anymore – a little “surprise” from Microsoft.
Contributions
* As Evon pointed in comments, Qt folder has huge size (approx. 7GB) after compilation. One can safely shrink its size by deleting temporary files created during the process. Once compiled Qt doesn’t depend on these intermediate files – and they can be erased without affecting Qt functionality. Run as last command in step 10:..\jom\jom.exe clean
Note that PDB files will be deleted too (the files are rarely needed, only for debugging of Qt itself).
** Rob provided his compilation script based on
nmakewith multi-core support.
http://www.holoborodko.com/pavel/2011/02/01/how-to-compile-qt-4-7-with-visual-studio-2010/
相关文章推荐
- How To Compile Qt with Visual Studio 2010
- How to compile WinPcap with Visual Studio 2010?
- How to compile a C/C++ DLL for 64 bit with Visual Studio?
- How to configure and use Git with visual studio 2012 and TFS
- How to Compile XviD with Microsoft Visual C++ 6.0
- How to import existing projects into TFS Visual Studio with GIT ?
- How to debug c++ console application with argument in visual studio 2012
- How to change the default browser to debug with in Visual Studio 2008?
- Translation:How to build Tesseract 3.03 with Visual Studio 2013 (翻译《VS2013 建立tesseract3.03工程》)
- How to Compile XviD with Microsoft Visual C++ 6.0(转)
- How to create a DLL with SWIG from Visual Studio 2010
- tesseract3.03:vs2013 + x64 / x86 +win7 + 《How to build tesseract 3.03 with Visual Studio 2013》
- How to Compile XviD with Microsoft Visual C++ 6.0(zhuan)
- How to build mscorlib.dll with visual studio
- How do I set up a Microsoft Visual Studio project to work with MATLAB Compiler 4.0?
- How to compile the IJG JPEG library (libjpeg) for Visual Studio 2010
- How to connect to MySQL database from Visual Studio VS2010 – problems with NET connectors
- How to create a project with existing folder of files in Visual Studio?
- How to connect to MySQL database from Visual Studio VS2010 – problems with NET connectors
- [ZZ]How To Compile Qt 4.7 with Visual Studio 2010