GrabDuck

Ubuntu cross compilation for Windows - RetroShare

:

This page explains how to compile RetroShare for windows on Ubuntu using cross-compilation with mingw. Basically, once your environmentn is properly set, you just have to qmake+make and you get a win32 exe.

Preparing the cross-compilation environment

Basics

> sudo apt-get install wine mingw32 mingw32-binutils mingw32-runtime

This is all what is needed for basic cross-compilation. Let's make a try:

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
  MessageBox(NULL,
    "Cette fenĂȘtre prouve que le cross-compilateur est fonctionnel !",
    "Hello World", MB_OK);
  return 0;
}

Compile this using:

> i586-mingw32msvc-g++ -o essai.exe essai.cpp

To execute, you need the mingw library: mingwm10.dll:

> gunzip -c /usr/share/doc/mingw32-runtime/mingwm10.dll.gz > mingwm10.dll

Then you can launch it:

> wine essai.exe

You should see a window in Windows style.

Installing the Qt4 environment

Let's get into more involved stuff, and install Qt libraries:

> sudo apt-get install libqt4-core libqt4-gui libqt4-qt3support libqt4-sql libqt4-debug-dev libqt4-dev

... as well as qt dev files for mingw:

> wget http://wftp.tu-chemnitz.de/pub/Qt/qt/source/qt-win-opensource-4.4.3-mingw.exe

... and extract them:

> wine qt-win-opensource-4.4.3-mingw.exe

Notes:

  • No need to download MinGW during the install
  • don't forget to register the dll's in wine's config, as proposed.

Now, copy the original spec file to the cross compilation environment:

> sudo cp -Rf /usr/share/qt4/mkspecs/win32-g++ /usr/share/qt4/mkspecs/win32-x-g++
> sudo vi /usr/share/qt4/mkspecs/win32-x-g++/qmake.conf

Now perform the following changes into qmake.conf:

QMAKE_CXX               = i586-mingw32msvc-g++

QMAKE_INCDIR            = /usr/i586-mingw32msvc/include/
QMAKE_INCDIR_QT         = /usr/local/qt4-w32/4.4.3/include
QMAKE_LIBDIR_QT         = /usr/local/qt4-w32/4.4.3/lib

QMAKE_LINK              = i586-mingw32msvc-g++

# ne pas oublier le -mwindows ici
QMAKE_LFLAGS            = -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mwindows

#isEqual(MINGW_IN_SHELL, 1) {
        QMAKE_DIR_SEP           = /
        QMAKE_COPY              = cp
        QMAKE_COPY_DIR          = cp -r
        QMAKE_MOVE              = mv
        QMAKE_DEL_FILE          = rm -f
        QMAKE_MKDIR             = mkdir -p
        QMAKE_DEL_DIR           = rm -rf
#} else {
#       QMAKE_COPY              = cp
#       QMAKE_COPY_DIR          = cp -r
#       QMAKE_MOVE              = mv
#       QMAKE_DEL_FILE          = rm -f
#       QMAKE_MKDIR             = mkdir -p
#       QMAKE_DEL_DIR           = rm -rf
#}

# Remove .exe and add -qt4
QMAKE_MOC               = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}moc-qt4
QMAKE_UIC               = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}uic-qt4

# Nothing looks like this, so I removed the .exe
QMAKE_IDC               = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}idc
QMAKE_RC                = i586-mingw32msvc-windres
QMAKE_STRIP             = i586-mingw32msvc-strip

From now on, Qt4 compilation looks like this:

qmake-qt4 -spec win32-x-g++
make

Sources :

Compiling libretroshare.a

Go to the libretroshare/src directory and type:

> qmake -spec win32-x-g++ CONFIG=release
> make

On my system, the last command called by the compilation is ar although it should be /usr/i586-mingw32msvc-ar, so I re-run this last command manually.

Compiling RetroShare.exe

Go to retroshare-gui/src, and type:

> qmake -spec win32-x-g++ CONFIG=release
> make

You should get a RetroShare.exe file in the release directory.