Building 64-bit Qt 4.7 using MinGW-w64
(Nov 12, 2010)I successfully built 64-bit Qt libraries using MinGW-w64. Although I had to change Qt source code, it was only one line of code in the current source tree of qt-mingw-w64. The steps I took to built 64-bit Qt are described below. Note that my explanation is a bit verbose, as those who just start using MinGW or Qt may need additional information.
- Obtain Qt 4.7 source code.
- Go to http://gitorious.org/+qt-mingw-w64/qt/qt-mingw-w64-qt
- Click on the 'Source tree' button. Note that you can directly go to this link. However, go to the link above allows you to read recent activities of Qt development that may related to you.
- On the right side, you see several 'branches'. As of Nov 12, 2010, the one you want to use is plain '4.7,' which already merges Webkit facility.
- Once you click on the '4.7' button, you probably need to wait a minute or two. This allows the server to create tar.gz for downloading. Basically, the package is prepared on the fly. This is how gitorious works.
- Unpack the source tree to your preferred folder. For this note, I unpacked it to 'F:\Qt\qt-4.7.1_mingw_w64.' This path is used here for a demonstration purpose.
- Fix file 'src\corelib\tools\qsimd.cpp' by changing line 289 from 'long tmp' to 'quint64 tmp,' as suggested by Jonathan Liu [ref]. See the ref for more information if you don't understand what I meant. Please note that if you get a newer Qt version, this problem may already be solved.
- Get MinGW-w64 from sourceforge. I use the native compiler for Windows 64-bit. FYI: MinGW offers a cross-compilation feature. You can use Linux or 32-bit Windows to produce 64-bit Windows binary.
- Go to http://sourceforge.net/projects/mingw-w64/files/
- Click on Section 'Toolchains targetting Win64'
- Pick the release you like. I suggest you use personal build from sezero, as sezero usually adds some patches or features that you might want to use (e.g., updated OpenGL and OpenCL headers). I employed mingw-w64-bin_x86_64-ming_20101003_sezero.zip. By the time you get MinGW from sourceforge, the build may be gone. Yet, you are supposed to get a newer version than mine.
- If you wonder what are inside each sezero build see his note in Section 'Toolchains targetting Win64 -> Personal Builds -> sezero_20101003.' sezero did a good job in bookkeeping (at least it seemed).
- Personal build of rubenvb is probably an interesting choice, as he appears to be a Qt contributor. I believe that his MinGW build should not have a serious issue with Qt compilation.
- Unpack MinGW to a preferred place. For this note, it is 'D:\mingw_w64_sezero_oct_3_2010.'
- Go to D:\mingw_w64_sezero_oct_3_2010\bin and change gmake.exe to mingw32-make.exe. Note that it is MinGW's gmake not Qt's qmake. I backed up original mingw32-make.exe to other file first, although they might be exactly the same binary in the sezero's build.
- Download Perl. Yes, you need Perl to syncqt during compilation. I suggest ActivePerl Community Edition. If you want to repeat what I did here, download Windows 64-bit version with an MSI installer. I did not like Strawberry Perl, as I encountered many issues with it during past summer, especially the fact that it comes with its own GCC. Its GCC confused me about GCC version since both Strawberry's and MinGW's GCC showed up in the path. These issues may be already resolved by now, though.
- Install Perl. What a simple task if you have admin right to your machine. If you don't, see steps below.
- Download AS Package (ZIP).
- Unpack and set path to 'base_perl_path/bin' and 'base_perl_path/site/bin.'
- If you want a temporary session path for your command prompt (cmd.exe), type 'set PATH=C:\Perl64\bin;C:\Perl64\site\bin;%PATH%, provided that you unpack its main contents to C:\Perl64 and discard its 'support' folder. Don't close this command prompt yet because your path settings are temporary. You need to use it until the end.
- Now, you have all you need to embark the actual compilation phase. Set path to your MinGW folder. For example, 'set PATH=D:\mingw_w64_sezero_oct_3_2010\bin;%PATH%.'
If you want to know what your current path is, type 'echo %PATH%.' - Set QTDIR variable by typing 'set QTDIR=F:\Qt\qt-4.7.1_mingw_w64\bin.'
- Go to Qt base folder (F:\Qt\qt-4.7.1_mingw_w64) and run configure from the command prompt. You can choose any configure options, perhaps except phonon (my Qt build did not have phonon). I used 'plain' configure that generated everything, but you might want to get rid of many things, especially qt3 support, examples, and demos.
Update (Feb 18, 2011): it is easy to build Qt with phonon. The option, however, is off by default for MinGW. I tested with
configure -opensource -phonon -no-qt3support -nomake example -nomake demos
Although I did not test if the created libraries work or not, things are built smoothly. - Type 'gmake.' Note that if you want to try multi-threaded compilation, type 'gmake -jx,' where x is the number of threads. For instance, 'gmake -j2' for a dual-core machine, 'gmake -j4' for a quad-core machine, and 'gmake -j6' for a six-core machine (if you want to put every core to work). I, however, just used gmake with no option since I wanted to simplify everything for this build.
- Wait with patience.
The following summarizes downloads and tweaks I made during the above steps. Basically, we need to do only two things in addition to what most people do with mingw 32-bit. I have not try building phonon yet (and I think I don't need it for a long time).
Download summary
- Qt 4.7 mingw-w64 branch (~ 130 MB). See step 1.
- MinGW-w64 (~ 55 MB). See step 4.
- ActivePerl (~ 24 MB). See step 7.
Tweak summary
- Change source code (1 file, 1 line). See step 3.
- Change gmake to mingw32-make.exe. See step 6. (May not be necessary any more.)
Hope this helps,
Pinyo Taeprasartsit
Additional reference: mingw-w64 mail archive
I welcome questions and comments. Feel free to ask and share if you have any.