this is deprecated and have been long replaced by the mingw-w64 packages.
For the longest time I used Mingw + cmake on top of wine to cross compile my Qt4 apps for windows, then I was bored one day, tired of how slow it is to recompile qt4 on wine and decided to try to get it to work with a native gcc instead of the overhead with wine.
So here goes.
This was done on Gentoo Linux, please don't ask me how to do it on other distros.
Assumptions :
1. You know your way around the linux shell and have portage privileges.
2. You're not scared from compiling things by hand.
3. You already have Qt4 installed and it is the same version as the windows source we gonna build.
4. Your working path will be ~/win32.
5. You have a working wine setup.
Part 1 - Meet the Toolchain :
1 2 3 4 5 6 7 8 |
# Change 32 to 64 if you're trying to build for Win64, of course you'd need a 64bit Linux toolchain as well. export cross=i686-pc-mingw32 emerge -av crossdev # I decided to use the latest gcc version, however there's nothing stopping you from using 3.x. # Start building the tool chain, go make some coffee, watch tv, or play a game until it's done. crossdev --gcc 4.4.2 ${cross} # Fix a bug in Qt4's corelib, also make sure to change 4.4.2 to whichever version of gcc you decided to use. ln -s /usr/${cross}/usr/include/float.h /usr/lib/gcc/${cross}/4.4.2/include/g++-v4 |
*Important* due to the way the gentoo build works, you have to use -static-libgcc while compiling with mingw's g++ to elemenate the dependacy on libgcc_s_sjlj-1.dll.
You don't need root access anymore.
Part 2 - OpenSSL Time :
The main reason I added this part is the fact my project relays heavly on crypto, so might as well have Qt4 built with OpenSSL support.
If you don't need crypto / https support in QtNetwork, you can skip this and pass -no-openssl to Qt's configure.exe below.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
mkdir ~/win32; cd ~/win32 # Download and unpack (0.9.8l was the latest stable version when I wrote this). wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz tar xzf openssl-0.9.8l.tar.gz && cd openssl-0.9.8l/ # A custom build script, based on other people's work + mailing list (check refs at the bottom) wget http://www.limitlessfx.com/uploads/mingw-openssl.sh.txt -O mingw-openssl.sh # play with the cflags and such vim mingw-openssl.sh # actually compile it. sh mingw-openssl.sh |
If all goes well you will have out/libeay32.dll and out/libssl32.dll which is all we need.
Part 3 - It's hammer time aka Qt4 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
cd ~/win32 wget http://get.qt.nokia.com/qt/source/qt-win-opensource-src-4.5.3.zip unzip qt-win-opensource-src-4.5.3.zip && cd qt-win-opensource-src-4.5.3 # Trick the buildsystem into using win32 feature files: cd mkspecs/features && ln -s win32 unix && cd ../.. # Use our custom qmake.conf *very* important, otherwise the build will fail. wget http://www.limitlessfx.com/uploads/win32-g++_qmake.conf -O mkspecs/win32-g++/qmake.conf # *IMPORTANT*, edit the file, scroll down to line 51 and change /home/dev/win32/openssl-0.9.8l/include/ to your real path. vim mkspecs/win32-g++/qmake.conf # Make sure qmake doesn't use compilation paths meant for unix find src -name '*.pro' -o -name '*.pri' | xargs sed -i -e 's/\(^\|[^_/]\)unix/\1linux/g;' # Make qmake use compilation paths meant for Windows. find src -name '*.pro' -o -name '*.pri' | xargs sed -i -e 's/\(^\|[^_/]\)win32\([^-]\|$\)/\1unix\2/g;' # Trick configure into using system utilities. for f in moc rcc uic qmake; do ln -s `which $f` bin; done # Make sure we don't build them: echo qmake: > qmake/Makefile.unix for f in `ls src/tools`; do echo TEMPLATE = subdirs > src/tools/$f/$f.pro; done # Now the fun begins, feel free to switch options around, we're *only* building the libs, feel free to remove -nomake tools if you need the tools. # Note that there's actually a . (dot) at the end of that line. wine configure.exe -release -platform win32-g++ -no-exceptions -ltcg -mmx -sse -sse2 -openssl -qt-libjpeg -qt-libpng -qt-zlib -no-accessibility -no-qt3support -no-phonon -no-phonon-backend -no-dbus -no-opengl -nomake examples -nomake demos -nomake translations -nomake docs -nomake tools -no-style-plastique -no-style-cleanlooks -no-style-cde -no-style-motif -no-sql-sqlite -no-scripttools -opensource -confirm-license -no-qmake -dont-process -qt-sql-sqlite -prefix . # Now, fix the wine paths in .qmake.cache: perl -pe 's/\w://g; s/\.exe//g;' -i .qmake.cache # Fix a minor bug in WebKit, since we're actually compiling on linux QWidget.h isn't the same as qwidget.h : sed -e 's/QWidget\.h/qwidget.h/' -i src/3rdparty/webkit/WebCore/plugins/win/PluginViewWin.cpp # Generate Makefiles. qmake -spec $PWD/mkspecs/win32-g++ -r projects.pro -o $PWD # Start compiling and pray : make # You can build specific parts if you want, for example to build QtCore, QtNetwork and QtWebKit you can do : make sub-corelib sub-network sub-webkit |
Well, if all went well up this point, you should have a working native Mingw + OpenSSL + Qt4 on linux without the need of using wine + gcc.
Check later for how to use it with cmake!
Enjoy.
References :
Mingw + Qt4 guide, their approche of using the linux version's configure script didn't work for me.
Mingw + OpenSSL guide, pretty much the build script I used minus some other fixes I found online.
OpenSSL mailing list.