Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cross compiling for win with mingw on linux.



  • Hi all,

    I am interesting to compile win app(qml) on linux with qt framework 5.4.1. I was able to compile icu, openssl and qt statically, and when i compiled some examples from qt directory: Examples\Qt-5.4\gui, Examples\Qt-5.4\qml most of them do not work, moreover some qt tools do not work too(how it looks like: appear for a moment and close silently or appears only white window). For example: tutorials\extending-qml\chapter1-basics. It shows only white window without content. I have two assumptions about this behavior. 1) for successful run i need to plug some of the dlls/plugins. 2) cross compiled qt was wrongly compiled/configured.
    I am interesting, does somebody encountered similar problem and may be someone was able to fix. Or generally, it is bad idea to compile win app on linux?

    MICRO_ARC=i686
    MINGW_COMPILER=$MICRO_ARC-w64-mingw32

    ICU

    git clone https://github.com/unicode-org/icu.git && cd ./icu && git checkout tags/release-57-1 && \
        mkdir build-lin build-win && \
        cd ~/icu/build-lin && ../icu4c/source/configure && make -j$(nproc) && \
        cd ~/icu/build-win && ../icu4c/source/configure --enable-static --disable-shared --host=$MINGW_COMPILER --with-cross-build=$PWD/../build-lin --prefix=$ICU_INSTALL_DIR && \
        make -j$(nproc) && make install
    

    OPENSSL

    git clone https://github.com/openssl/openssl.git && cd ./openssl && git checkout tags/OpenSSL_1_0_2 && \
        TYPE=$(case $MICRO_ARC in (*i?86*) echo mingw ;; (*x86_64*) echo mingw64 ;; (*) false;; esac) && \
        ./Configure no-asm no-shared $TYPE --cross-compile-prefix=$MINGW_COMPILER- --prefix=$OPENSSL_INSTALL_DIR && make && make install
    

    QT
    Added at the end of files these lines: qt5/qtbase/mkspecs/win32-g++/qmake.conf
    QMAKE_LFLAGS += -static -static-libgcc
    QMAKE_CFLAGS_RELEASE -= -O2
    QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer -ldl
    DEFINES += QT_STATIC_BUILD

    export OPENSSL_LIBS='-lssl -lcrypto -lgdi32' && cd ~/qt5 && \
        ./configure \
            -static \
            -release \
            -xplatform win32-g++ \
            -device-option CROSS_COMPILE=$MINGW_COMPILER- \
            -device-option PKG_CONFIG=$MICRO_ARC-w64-mingw32-pkg-config -force-pkg-config \
            -prefix $QT_INSTALL_DIR \
            -opensource -confirm-license -optimized-qmake \
            -reduce-exports -reduce-relocations \
            -qt-pcre -make libs \
            -make tools -qt-libpng -qt-libjpeg \
            -no-compile-examples -nomake examples -nomake tests \
            -icu -I $ICU_INSTALL_DIR/include -L $ICU_INSTALL_DIR/lib \
            -openssl-linked -I $OPENSSL_INSTALL_DIR/include -L $OPENSSL_INSTALL_DIR/lib \
            -skip qtactiveqt -skip qtdoc 2>&1 | tee config.out && \
        make -j$(nproc) && make install -j$(nproc)
    

  • Lifetime Qt Champion

    Hi,

    It would be way simpler to directly built your application on Linux.

    Cross-compilation from Windows to Linux is really much more trouble than using a virtual machine with Linux installed.


  • Lifetime Qt Champion

    Hi @Andeksan,

    you can checkout the MXE cross environment for cross-compiling from Linux to Windows. It automates most of the boring stuff.

    Regards



  • Thanks for replies, now i understand that, generally this approach does not worth to spend time. Probably i will change my focus on wine+installed qt. it should be more reliable variant.


Log in to reply