here is a guide for it
Installing the Qt libraries into Wine
Now download the Qt SDK and install it into the wine environment.
At the time of this writing, we only tested version 4.7.4, but you can
grab the latest version from the nokia website. For the sake of
compatibility, make sure you download the same version as the one
which comes with your Ubuntu version: check it here.
cd /tmp
wget http://get.qt.nokia.com/qt/source/qt-win-opensource-4.7.4-mingw.exe
wine qt-win-opensource-4.7.4-mingw.exe
The last command will launch the installer as if it was on a Windows
environment. Do NOT run it as sudo! During the install you will be
prompted that MinGW is missing: this is perfectly normal and can be
ignored.
After the successful install we need to set the environment variable PATH in Wine, as it, for some reason, is not set automatically by the Qt installer. Simply run:
wine regedit
and browse to "HKEY_CURRENT_USER/Environment". Right click and add a new string value with name "Path". Double click on it to edit and set its value to "c:\windows;c:\windows\system;c:\Qt\4.7.4\bin". Refer to the Wine User Guide for further details on how to set environmental variables.
Defining the cross-compilation qmake environment
Now for the tricky part. Qt programs are usually compiled with qmake, which takes care of setting the right compiler options. For this purpose some specific config files are required for the target platform. We need to create such a config file, tailored for cross-compilation. As a template we will use the win32 config file, so let's make a copy of the related environment first:
cp -Rfp /usr/share/qt4/mkspecs/win32-g++ /usr/share/qt4/mkspecs/win32-x-g++
We have to edit /usr/share/qt4/mkspecs/win32-x-g++/qmake.conf and replace the default compilers gcc and g++ with the cross-compilers provided by the MinGW package, along with other options. Ours looks like this:
#
# qmake configuration for win32-g++
#
# Written for MinGW
#
MAKEFILE_GENERATOR = MINGW
TEMPLATE = app
CONFIG += qt warn_on release link_prl copy_dir_files debug_and_release debug_and_release_target precompile_header
QT += core gui
DEFINES += UNICODE QT_LARGEFILE_SUPPORT
QMAKE_COMPILER_DEFINES += __GNUC__ WIN32
QMAKE_EXT_OBJ = .o
QMAKE_EXT_RES = _res.o
QMAKE_CC = i586-mingw32msvc-gcc
QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = byacc
QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS =
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -Wall
QMAKE_CFLAGS_WARN_OFF = -w
QMAKE_CFLAGS_RELEASE = -O2
QMAKE_CFLAGS_DEBUG = -g
QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses
QMAKE_CXX = i586-mingw32msvc-g++
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_RTTI_ON = -frtti
QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
QMAKE_INCDIR = /usr/i586-mingw32msvc/include/
QMAKE_INCDIR_QT = /home/matteo/.wine/drive_c/Qt/4.7.4/include
QMAKE_LIBDIR_QT = /home/matteo/.wine/drive_c/Qt/4.7.4/lib
QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -o $obj $src
QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src
QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
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_LFLAGS_EXCEPTIONS_ON = -mthreads -Wl
QMAKE_LFLAGS_EXCEPTIONS_OFF =
QMAKE_LFLAGS_RELEASE = -Wl,-s
QMAKE_LFLAGS_DEBUG =
QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,console
QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows
QMAKE_LFLAGS_DLL = -shared
QMAKE_LINK_OBJECT_MAX = 10
QMAKE_LINK_OBJECT_SCRIPT= object_script
QMAKE_LIBS =
QMAKE_LIBS_CORE = -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
QMAKE_LIBS_GUI = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lws2_32 -lole32 -luuid -luser32 -ladvapi32
QMAKE_LIBS_NETWORK = -lws2_32
QMAKE_LIBS_OPENGL = -lglu32 -lopengl32 -lgdi32 -luser32
QMAKE_LIBS_COMPAT = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32
QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain
#!isEmpty(QMAKE_SH) {
MINGW_IN_SHELL = 1
QMAKE_DIR_SEP = /
QMAKE_QMAKE ~= s,\\\\,/,
QMAKE_COPY = cp
QMAKE_COPY_DIR = xcopy /s /q /y /i
QMAKE_MOVE = mv
QMAKE_DEL_FILE = rm
QMAKE_MKDIR = mkdir
QMAKE_DEL_DIR = rmdir
QMAKE_CHK_DIR_EXISTS = test -d
#} else {
# QMAKE_COPY = copy /y
# QMAKE_COPY_DIR = xcopy /s /q /y /i
# QMAKE_MOVE = move
# QMAKE_DEL_FILE = del
# QMAKE_MKDIR = mkdir
# QMAKE_DEL_DIR = rmdir
# QMAKE_CHK_DIR_EXISTS = if not exist
#}
QMAKE_MOC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}moc-qt4
QMAKE_UIC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}uic-qt4
QMAKE_IDC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}idc-qt4
QMAKE_IDL = midl
QMAKE_LIB = ar -ru
QMAKE_RC = i586-mingw32msvc-windres
QMAKE_ZIP = zip -r -9
QMAKE_STRIP = i586-mingw32msvc-strip
QMAKE_STRIPFLAGS_LIB += --strip-unneeded
load(qt_config)
Tip: if you encounter any problems while setting up the config file, have a look at the script which comes with this tutorial, which automates every single step.
Bonus: set up a cross-architecture environment
Many new machines are built with a 64-bit architecture. If you are developing on one of these, chances are that you also want to produce 32-bit binaries that can be run on older computers. This is easily achieved, because the Ubuntu package provides both versions of the libraries. There is only one line to be added to the config file, do it by running:
echo "QMAKE_LIBDIR_QT = /usr/lib32/" >>/usr/share/qt4/mkspecs/linux-g++-32/qmake.conf
As for the windows environment, Nokia only provides 32-bit versions of the Qt libraries, which should already be compatible with both architectures. The setup we presented will already produce this kind of executables. If you want to optimize the binaries for 64-bit environments there are a few options:
Acquire a payed license for Qt from Nokia. Their support desk will then provide 64-bit binaries upon request.
Download the source code from the Nokia website, and compile Qt yourself for 64-bit environments.
Download and install unofficial (untrusted!) binaries you might be able to find in the Internet.