Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Building Qt6 for Windows from Linux

Building Qt6 for Windows from Linux

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
mingw64crosscompile
2 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    plaristote
    wrote on 13 Feb 2023, 13:40 last edited by plaristote
    #1

    Greetings !

    I'm trying to create a Docker machine that would be able to build my Qt applications for Windows.

    I've been using the following article which describes how to do it for Qt5 with Ubuntu: https://medium.com/@vladadgad/cross-compile-qt-for-windows-on-linux-platform-57e4b71ed1aa

    Expanding on the instructions from this tutorial, here's the command that I used to configure the build:

    QT_VERSION=6.4.2
    INSTALL_PREFIX=/opt/webapp/builder
    
    mkdir -p $INSTALL_PREFIX/usr/Qt/$QT_VERSION/x86_64-w64-mingw64
    
    ./configure -opensource -confirm-license \
      -c++std c++17 \
      -xplatform win32-g++ \
      -device-option CROSS_COMPILE=/usr/bin/x86_64-w64-mingw32 \
      -prefix $INSTALL_PREFIX/usr/Qt/$QT_VERSION/x86_64-w64-mingw32  \
      -nomake examples
    

    The configuration has gone smoothly, but it seems like mingw isn't being used when building. When I run the cmake --build . command with the VERBOSE=1 environment variable, I can see that files are compiled with /usr/bin/c++. Here's an example of the full command:

    /usr/bin/c++ -DHAVE_CONFIG_H -DQT_BOOTSTRAPPED -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_FOREACH -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_TYPESAFE_FLAGS -DQT_USE_QSTRINGBUILDER -DQT_VERSION_MAJOR=6 -DQT_VERSION_MINOR=4 -DQT_VERSION_PATCH=2 -DQT_VERSION_STR=\"6.4.2\" -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/Core_autogen/include -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/include -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/include/QtCore -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/global -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/kernel -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/../3rdparty/tinycbor/src -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/include/QtCore/6.4.2 -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/include/QtCore/6.4.2/QtCore -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/../3rdparty/double-conversion/double-conversion -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/../3rdparty/double-conversion -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/../3rdparty/forkfd -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/.rcc -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/mkspecs/win32-g++ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/tools/bootstrap/.. -I/opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/tools/bootstrap/../../3rdparty/tinycbor/src -DNDEBUG -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -ffunction-sections -fdata-sections -mshstk -Wsuggest-override -fcf-protection -MD -MT qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qrandom.cpp.o -MF qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qrandom.cpp.o.d -o qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qrandom.cpp.o -c /opt/webapp/builder/Qt/6.4.2/Src/qtbase/src/corelib/global/qrandom.cpp
    

    This fails to compile, claiming the tchar.h header is missing, which makes sense, since this header only exists for Windows (or at least that's what I've read).

    I've modified the same command by replacing /usr/bin/c++ with /usr/bin/x86_64-w64-mingw32-g++ -std=c++17, and it seems to work... at least for qrandom.cpp !

    I also tried to unlink /usr/bin/{c++,cc,ar,nm} and relink it to the ones provided by mingw, but then the configuration step fails, claiming that some linux-related headers are missing. Well... d'uh ! But why are we looking for these when xplatform is set to win32-g++ ?
    Alternatively, I can also configure first, and only then override the system compiler for mingw; but then, the build tries to include some linux-specific headers.

    Any guidance on this topic will be very appreciated ! And I'm sure a Docker machine capable of cross-compiling Qt projects for Windows will have its use for many of us, if we can get this thing working !

    1 Reply Last reply
    1
    • K Offline
      K Offline
      KH-219Design
      wrote on 13 Feb 2023, 18:20 last edited by
      #2

      My reply is going to lead down a bit of a tangent...

      If someone knows how to give you a more direct answer, then I would recommend you ignore mine!

      I don't have a direct answer. But I have a long-standing curiosity about cross-platform development, so I took a moment to do a brief investigation.

      When I need a point of reference for using Qt in a "massively cross platform" way, my "cheatsheet" that I often turn to is the Subsurface divelog project.

      They are cross-compiling their Qt app on Linux to target windows. You can see their CI job config here. I know that's not the same as cross-compiling Qt itself.

      However, I noticed (at the top of one of their scripts) that they call out how they are leveraging: https://github.com/mxe/mxe

      And when I read the MXE page, I see they say: "MXE (M cross environment) is a GNU Makefile that compiles a cross compiler and cross compiles many free libraries such as SDL and Qt. "

      Again, this is a very indirect stab and a mostly non-answer.

      But if you end up in dead ends with anything you try, maybe MXE would give you a path forward.

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      1 Reply Last reply
      0

      2/2

      13 Feb 2023, 18:20

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved