
Qt & Ubuntu. Set up the environment for compiling win32 applications

This mini-article talks about one way to cross-compile Qt applications for the win32 platform.
Let's get started, friends.
Let's start by downloading and installing the native Qt SDK (for Linux).
Alternatively, execute in the console:
wget get.qt.nokia.com/qtsdk/qt-sdk-linux-x86-opensource-2010.04.binI put the Qt SDK Linux in the folder "/ home / caiiiycuk / qt-cross / qt-linux", so be careful about the paths.
chmod 777 qt-sdk-linux-x86-opensource-2010.04.bin
./qt-sdk-linux-x86-opensource -2010.04.bin
The next stage is perhaps the most problematic - we need to get compiled Qt libraries for the target platform (windows). There are two options: either compile them using cross-compilation from source (which, it seems to me, will be very difficult); either put the Qt SDK on some win-machine, and then carefully transfer the dad from Qt to the native system. I went the second way and the Qt SDK for Windows settled comfortably 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 mingw32At the end of the installation, the i586-mingw32msvc- * toolkit will be available, with which we will compile for the win32 platform.
As an application for a cross-compilation example, I use fancybrowser (qt-linux / qt / examples / webkit / fancybrowser) copied to the folder "/ home / caiiiycuk / qt-cross / fancybrowser". As you understand, you can use any other project - just my eye fell on him :)
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)
We compile under Linux
Well, let's start with a simple one - compile the project using qt-linux (i.e. for a linux system):
// actions are performed from the directory / home / caiiiycuk / qt-cross / fancybrowserSimple, right? :) The output will be the fancybrowser executable. Running it, we will see something like:
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

Compile under Windows
So it is time to compile under win32. First, create a specification file that explains Qt how to compile under Windows. To make your life easier, copy the existing win32-g ++ specification file
cd qt-win / qt / mkspecs /
mkdir win32-x-g ++
cp win32-g ++ / * win32-x-g ++ /
We will 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_LIBcuk qtqqiqt qqiqt qqiqt qqiqi qtqq qi qi qt q -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 -ntlnt -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 / fancybrowAfter successful compilation, the cherished fancybrowser.exe will lie in the release folder.
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
That's all business :) We don’t forget that you need to have the required dlls to start (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 can not guarantee that this is the “true way” for cross-compiling qt applications, this is just my research. I would be grateful for any criticism :) The performance of this method was also tested on OpenSuse and CentOS. Ubuntu was only better because its repository contained mingw32 of a later version. I don’t 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 another article. Thanks to all :)