Skip to content
Dan Parnham edited this page Mar 6, 2018 · 4 revisions

Notes on cross-compilation

Here are my notes on cross-compilation (building Windows libraries and apps on Ubuntu), mostly for a my own reference but they may prove useful to others. These instructions are for building a 64-bit application, but should apply to 32-bit as well.

Libraries

Setup

  • Install mingw-w64 from repos.
  • Install the latest premake5 binary.
  • Download FreeImage and libusb-1.0 Windows binaries.
  • Extract and either copy or symlink the following:
    • libusb/include/libusbx-1.0 to /usr/x86_64-w64-mingw32/include/libusb-1.0
    • libusb/MinGW64/dll/libusb-1.0.dll to /usr/x86_64-w64-mingw32/lib/
    • FreeImage/Dist/x64/FreeImage.h to /usr/x86_64-w64-mingw32/include/
    • FreeImage/Dist/x64/FreeImage.dll to /usr/x86_64-w64-mingw32/lib/freeimage.dll

Switch mingw-w64 to the posix version:

$ sudo update-alternatives --config x86_64-w64-mingw32-g++
$ sudo update-alternatives --config x86_64-w64-mingw32-gcc

and then choose the posix option in both cases.

libemergent

Clone libemergent and then make sure the headers are available on the include path, for example by copying or symlinking: libemergent/include/emergent to /usr/x86_64-w64-mingw32/include/

libpsinc

$ cd libpsinc
$ premake5 --os=windows gmake
$ make CXX=x86_64-w64-mingw32-g++

Optionally, make it available to other projects as with libemergent.

Applications

Qt

To build iconograph you will need a working build of Qt5. Here is how to create a version with minimal dependencies suitable for cross-compilation.

$ git clone git://code.qt.io/qt/qt5.git
$ cd qt5
$ git checkout 5.5
$ ./init-repository

Then use the following script to configure it (easier to keep it in a script in case you wish to customise the build further).

#!/bin/bash

./configure -make libs -nomake examples -nomake tests -device-option \
    CROSS_COMPILE=x86_64-w64-mingw32- -xplatform win32-g++ \
    -qt-zlib -qt-libpng -qt-freetype -qt-harfbuzz -qt-pcre \
    -no-glib -no-icu -no-iconv -no-dbus -no-qml-debug \
    -skip qtconnectivity -skip qtwebkit -skip qtactiveqt -skip qtcanvas3d \
    -opensource -confirm-license -release -prefix /opt/qt5-win-x64

After running the script you can call make and then go and have a cup of tea.

Finally sudo make install will install all appropriate files to "/opt/qt5-win-x64".

iconograph

To then build a Qt application such as iconograph:

$ cd libpsinc
$ PATH=/opt/qt5-win-x64/bin:$PATH qmake -spec win32-g++ -o iconograph.make iconograph.pro
$ make -f iconograph.make

Deployment

To actually run on Windows a number of libraries will need to be included (ubuntu 16.04):

  • libgcc_s_seh-1.dll can be found in /usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/
  • libstdc++-6.dll can be found in /usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/
  • libwinpthread-1.dll can be found in /usr/x86_64-w64-mingw32/lib/
  • FreeImage.dll, libusb-1.0.dll and psinc.dll can be found as described above.
  • Qt5Core.dll, Qt5Gui.dll and Qt5Widgets.dll can be found in qt5/qtbase/lib
  • platforms/qwindows.dll can be found in qt5/qtbase/plugins