
This mini article talks about one way to cross-compile Qt applications for the win32 platform.
Let's start friends')
Let's start by downloading and installing the native Qt SDK (for Linux).
As an option - run in the console:
wget get.qt.nokia.com/qtsdk/qt-sdk-linux-x86-opensource-2010.04.bin
chmod 777 qt-sdk-linux-x86-opensource-2010.04.bin
./qt-sdk-linux-x86-opensource-2010.04.bin
I put Qt SDK Linux in the folder "/ home / caiiiycuk / qt-cross / qt-linux", so be attentive to the paths.
The next stage is perhaps the most problematic - we need to get the compiled Qt libraries for the target platform (windows). There are two options: either compile them using cross-compilation from source (which, I think, will not be very easy); or put the Qt SDK on any win-machine, and then carefully transfer the daddy from Qt to the native system. I went the second way and the Qt SDK for Windows is cozily settled in the daddy / home / caiiiycuk / qt-cross / qt-win.
Ok, now let's set up the windows compilation environment. Install the mingw compiler from the Ubuntu repository:
sudo apt-get install mingw32
After the installation is complete, the i586-mingw32msvc- * toolkit will be available, which we will compile for the win32 platform.
As an application for the example of cross-compilation, I use fancybrowser (qt-linux / qt / examples / webkit / fancybrowser), copied to the folder "/ home / caiiiyk / qt-cross / fancybrowser". As you understand, you can use any other project - just my eye fell on it :)
Thus , we have:
- Qt SDK for Linux, in the folder "/ home / caiiiycuk / qt-cross / qt-linux"
- Qt SDK for Windows in the folder "/ home / caiiiycuk / qt-cross / qt-win"
- Test application "fancybrowser", in the folder "/ home / caiiiycuk / qt-cross / fancybrowser"
- Gcc / g ++ 4.4.3 compiler (shipped with Ubuntu)
- Compiler i586-mingw32msvc-gcc / i586-mingw32msvc-g ++ (installed from the Ubuntu repository)
Compile for linuxWell, let's start with a simple one - compile the project using qt-linux (i.e., for the linux system):
// actions are performed from the directory / home / caiiiycuk / qt-cross / fancybrowser
export QTDIR = / home / caiiiycuk / qt-cross / qt-linux / qt
export QMAKESPEC = / home / caiiiycuk / qt-cross / qt-linux / qt / mkspecs / linux-g ++ - 32
$ QTDIR / bin / qmake
make clean
make
Simple, isn't it? :) At the output we get the executable file fancybrowser. Running it, we will see something like:
Compile under WindowsSo it is time to compile under win32. First, create a specification file that explains Qt how to compile on Windows. To make your life easier, copy the already existing win32-g ++ specification file.
cd qt-win / qt / mkspecs /
mkdir win32-x-g ++
cp win32-g ++ / * win32-x-g ++ /
We make the necessary corrections to the win32-x-g ++ / qmake.conf file:
QMAKE_SH = sh
...
QMAKE_CC = i586-mingw32msvc-gcc
...
QMAKE_CXX = i586-mingw32msvc-g ++
...
QMAKE_INCDIR_QT = / home / caiiiycuk / qt-cross / qt-win / qt / include
QMAKE_LIBDIR_QT = / home / caiiiycuk / qt-cross / qt-win / qt / lib
...
QMAKE_LINK = i586-mingw32msvc-g ++
QMAKE_LINK_C = i586-mingw32msvc-gcc
QMAKE_LFLAGS = -mthreads -Wl, -enable-stdcall-fixup -Wl, -enable-auto-import -Wl, -enable-runtime-pseudo-reloc -mwindows
...
QMAKE_MOC = / home / caiiiycuk / qt-cross / qt-linux / qt / bin / moc
QMAKE_UIC = / home / caiiiycuk / qt-cross / qt-linux / qt / bin / uic
QMAKE_IDC = / home / caiiiycuk / qt-cross / qt-linux / qt / bin / idc
...
QMAKE_RC = i586-mingw32msvc-windres
...
QMAKE_STRIP = i586-mingw32msvc-strip
...
Now you can compile:
// actions are performed from the directory / home / caiiiycuk / qt-cross / fancybrow
export QTDIR = / home / caiiiycuk / qt-cross / qt-win / qt
export QMAKESPEC = / home / caiiiycuk / qt-cross / qt-win / qt / mkspecs / win32-x-g ++
/ home / caiiiycuk / qt-cross / qt-linux / qt / bin / qmake
make clean
make
After successful compilation in the release folder there will be a cherished fancybrowser.exe. Total and business :)
Do not forget that to run you must have the required dll (for fancybrowser - QtCore4.dll QtGui4.dll QtNetwork4.dll QtWebKit4.dll QtXmlPatterns4.dll phonon4.dll mingwm10.dll libgcc_s_dw2-1.dll). These libraries can be taken from the qt-win / qt / bin folder but not from the qt-win / bin folder. The result should be this:

I cannot guarantee that this is a “true way” for cross-compiling qt applications, these are just my research. I would be grateful for any criticism :) The efficiency of this method was also tested on OpenSuse and CentOS. Ubuntu was better only because its repository contains a later version of mingw32. I do not know what it is connected with - a trifle, but nice.
These scripts (for compilation) can be easily integrated into Hudson, to facilitate the assembly of cross-platform products, but this is a topic for a separate article. Thanks to all :)