Building Qt 5 on Linux, for Windows

送分小仙女□ 提交于 2019-11-26 17:01:55

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.

AcidTonic

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.

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

su
mv mxe /opt/mxe
cd /opt/mxe && make
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!