简体   繁体   English

在 Linux 上构建 Qt 5,适用于 Windows

[英]Building Qt 5 on Linux, for Windows

I wanted to migrate my Qt 4 app to use Qt 5 instead.我想迁移我的 Qt 4 应用程序以使用 Qt 5。 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.这些指令失败了,因为MXE构建 Qt 5 的方式存在一些差异,包括它使用模块化 Qt tarball 而不是一个大 tarball 的事实。

Here are the full instructions:以下是完整说明:

  • Get it:得到它:

     git clone https://github.com/mxe/mxe.git
  • Install build dependencies安装构建依赖

  • Build Qt 5 for Windows:为 Windows 构建 Qt 5:

     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.由于 Qt 5 的新模块化特性,各种主要的 Qt 组件现在位于不同的 tarball 中。 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.上面选择的qtbase应该为您提供足够的功能来运行普通的 GUI 应用程序,这是我自己的(小型)应用程序所需要的。

    If you want to build all of Qt 5 instead, you'll need to run make qt5 (instead of make qtbase ).如果您想构建所有 Qt 5,则需要运行make qt5 (而不是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:进入你的应用程序目录,并运行 Qt Makefile 生成器工具:

     <mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5
  • Build your project:构建你的项目:

     make
  • You should find the binary in the ./release directory:您应该在 ./release 目录中找到二进制文件:

     wine release/foo.exe

Some notes:一些注意事项:

  • This was tested on my 64-bit Debian 8, and on Windows of course.这是在我的 64 位 Debian 8 和 Windows 上测试的。

  • The output is a 32-bit static executable, which will work well on 64-bit Windows.输出是一个 32 位静态可执行文件,它将在 64 位 Windows 上运行良好。

  • If you want a 64-bit executable, build Qt with:如果您想要 64 位可执行文件,请使用以下命令构建 Qt:

     make MXE_TARGETS=x86_64-w64-mingw32.static qtbase

    The default MXE_TARGETS value is i686-w64-mingw32.static .默认MXE_TARGETS值为i686-w64-mingw32.static

The git checkout command is not correct. git checkout 命令不正确。 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.仅此一项就解决了我在构建 qtbase 时遇到的所有问题,但完成后没有留下任何 qt 文件夹。 Then qt5 target would fail with obscure errors.然后 qt5 目标将失败并出现模糊错误。 Deleted folder, checked out stable and it worked flawlessly.删除文件夹,检查稳定,它工作完美。

For those who directly want a GCC10 64bit compiled Qt5 (for filesystem lib for example), Here are the full instructions:对于那些直接想要 GCC10 64 位编译的 Qt5(例如文件系统库)的人,以下是完整说明:

Get it:得到它:

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

Install build dependencies安装构建依赖

Build Qt 5 for Windows with gcc10 64bits plugin activated :为 Windows 构建 Qt 5 并激活 gcc10 64 位插件:

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) :构建 2-3 小时后,您可以构建您的应用程序(在您的 .pro 目录中):

<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) :您应该在 ./release 目录中找到二进制文件并使用 wine(或 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 :我真的不知道为什么,但我需要将 MXE 编译器目录添加到 wine 路径中,因为它找不到 DLL:

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

If you try to do this, for me work fine!如果你尝试这样做,对我来说工作正常!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM