63

I wanted to migrate my Qt 4 app to use Qt 5 instead. These instructions failed, due to some differences with how MXE builds Qt 5, including the fact that it uses modularised Qt tarballs, instead of one large tarball.

Community
  • 1
  • 1
tshepang
  • 12,111
  • 21
  • 91
  • 136

4 Answers4

110

Here are the full instructions:

  • Get it:

    git clone https://github.com/mxe/mxe.git
    
  • Install build dependencies

  • Build Qt 5 for Windows:

    cd mxe && make qtbase
    

    This will first build its dependencies and the cross-build tools; It should take less than an hour on a fast machine with decent internet access.

    Due to the new modular nature of Qt 5, various major Qt components are now in different tarballs. The one selected above, qtbase, should give you enough functionality to run ordinary GUI apps, which is all I needed for my own (smallish) app.

    If you want to build all of Qt 5 instead, you'll need to run make qt5 (instead of make qtbase). Note that it will take a lot longer to complete, so be sure that you need the extra functionality.

  • Get to the directory of your app, and run the Qt Makefile generator tool:

    <mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5
    
  • Build your project:

    make
    
  • You should find the binary in the ./release directory:

    wine release/foo.exe
    

Some notes:

  • This was tested on my 64-bit Debian 8, and on Windows of course.

  • The output is a 32-bit static executable, which will work well on 64-bit Windows.

  • If you want a 64-bit executable, build Qt with:

    make MXE_TARGETS=x86_64-w64-mingw32.static qtbase
    

    The default MXE_TARGETS value is i686-w64-mingw32.static.

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • How can you change the directories that mxe qmake spits stuff out into? I have my typical qmake producing files and folders in ./build but the mxe qmake litters my project root directory –  May 23 '14 at 06:05
  • 1
    Have you found an answer yet? If not, I don't know, and maybe ask that as a separate Question. – tshepang Nov 11 '14 at 08:59
  • Definitely use msys2 instead of MXE. With msys2 you can install prebuilt mingw32 and mingw64 binaries of qt with a single command `pacman -S mingw32/mingw-w64-i686-qt-creator` or `pacman -S mingw64/mingw-w64-x86_64-qt-creator` –  Nov 11 '14 at 16:32
  • 1
    @MiyazawaKenji MSYS2 looks very promising but it doesn't fit this particular question since it only runs on Windows, not Linux. Remember, MXE cross-compiles the libraries. – Nathan Osman Mar 04 '15 at 07:25
  • Console app works fine. But with a more complicated (QtWebkit+Gui) the app fails to start on windows: could not find or load Qt platform plugin "windows" – relascope Jun 11 '15 at 11:41
  • @relascope Last I checked the GUI worked. Maybe something changed since then. – tshepang Jun 11 '15 at 11:54
  • @Tshepang how did you deploy the app? searching for every dll it uses and copy them to app-dir, then again for the plugins? how do you find the dependencies? (DependencyWalker for Linux?) is there a "windeployqt" on linux? thx... would be nice to build from linux. at the time of writing I'm sticking with vagrant and two virtual machines: 1. WinXp+QT running windeployqt 2. WinXP for test... – relascope Jul 03 '15 at 00:34
  • 1
    @relascope it's built statically, so no dll things; you just deploy by placing the one executable wherever. – tshepang Jul 04 '15 at 00:44
  • 9
    Don't forget to export the path `$ export PATH=/usr/bin:$PATH` – Amit Tomar Sep 18 '15 at 12:38
  • 2
    Several years on, and your answer is still relevant and a godsend. I just tested it, MXE in WSL, using qtcreator to create static linked Windows executables, and non-static Linux ones. Thanks! – Waleed Hamra Apr 04 '18 at 16:40
  • I am getting error. No `filesystem` file or directory. Please help. – abhiarora Aug 22 '19 at 15:05
8

The git checkout command is not correct. You now have to get their stable branch or it will fail building.

git clone https://github.com/mxe/mxe.git

should be...

git clone -b stable https://github.com/mxe/mxe.git

That alone fixed all my issues with qtbase building but leaving no qt folder when done. Then qt5 target would fail with obscure errors. Deleted folder, checked out stable and it worked flawlessly.

tshepang
  • 12,111
  • 21
  • 91
  • 136
AcidTonic
  • 171
  • 1
  • 7
  • 2
    I guess it was just a temporary problem... `master` works now, and I don't actually remember the time when it failed, though I mostly build `qtbase`, not the larger `qt5`. – tshepang Dec 04 '14 at 08:26
  • 1
    git clone -b stable https://github.com/mxe/mxe.git is not working for me – j35t3r Jan 05 '17 at 18:13
  • 4
    @j35t3r I don't think a `stable` branch exists anymore. – Marcus Jul 21 '17 at 10:58
1

For those who directly want a GCC10 64bit compiled Qt5 (for filesystem lib for example), Here are the full instructions:

Get it:

git clone https://github.com/mxe/mxe.git

Install build dependencies

Build Qt 5 for Windows with gcc10 64bits plugin activated :

cd mxe && make MXE_TARGETS=x86_64-w64-mingw32.shared MXE_PLUGIN_DIRS=plugins/gcc10 qt5

After 2-3 hours of build you can build your app (in your .pro directory) :

<mxe root>/usr/x86_64-w64-mingw32.shared/qt5/bin/qmake

Export path of compiler & build your project:

export PATH=<mxe root>/usr/bin:$PATH
make

You should find the binary in the ./release directory & start it with wine (or wine64) :

wine foo.exe

I don't really know why, but I needed to add the MXE compiler directory to the wine path because it's couldn't find the DLLs :

WINEPATH="<mxe root>/usr/x86_64-w64-mingw32.shared/bin/" wine64 foo.exe 
0

If you try to do this, for me work fine!

su
mv mxe /opt/mxe
cd /opt/mxe && make