如何配置 Qt 以进行从 Linux 到 Windows 目标的交叉编译? [英] How do I configure Qt for cross-compilation from Linux to Windows target?

查看:40
本文介绍了如何配置 Qt 以进行从 Linux 到 Windows 目标的交叉编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Linux x86_64 主机为 Windows x86_64 目标交叉编译 Qt 库(以及最终我的应用程序).我觉得我很接近,但我可能对这个过程的某些部分有根本的误解.

I want to cross compile the Qt libraries (and eventually my application) for a Windows x86_64 target using a Linux x86_64 host machine. I feel like I am close, but I may have a fundamental misunderstanding of some parts of this process.

我首先在我的 Fedora 机器上安装所有 mingw 包,然后修改 win32-g++ qmake.conf 文件以适应我的环境.然而,我似乎被一些看似明显的 Qt 配置选项卡住了:-platform-xplatform.Qt 文档说 -platform 应该是主机架构(您正在编译的地方),而 -xplatform 应该是您希望部署的目标平台.就我而言,我设置了 -platform linux-g++-64-xplatform linux-win32-g++,其中 linux-win32-g++ 是我修改后的 win32-g++ 配置.

I began by installing all the mingw packages on my Fedora machine and then modifying the win32-g++ qmake.conf file to fit my environment. However, I seem to be getting stuck with some seemingly obvious configure options for Qt: -platform and -xplatform. Qt documentation says that -platform should be the host machine architecture (where you are compiling) and -xplatform should be the target platform for which you wish to deploy. In my case, I set -platform linux-g++-64 and -xplatform linux-win32-g++ where linux-win32-g++ is my modified win32-g++ configuration.

我的问题是,在使用这些选项执行 configure 后,我发现它调用了我系统的编译器而不是交叉编译器 (x86_64-w64-mingw32-gcc).如果我省略 -xplatform 选项并将 -platform 设置为我的目标规范(linux-win32-g++),它会调用交叉编译器,但是当它找到一些 Unix 时会出错相关功能未定义.

My problem is that, after executing configure with these options, I see that it invokes my system's compiler instead of the cross compiler (x86_64-w64-mingw32-gcc). If I omit the -xplatform option and set -platform to my target spec (linux-win32-g++), it invokes the cross compiler but then errors when it finds some Unix related functions aren't defined.

这是我最近尝试的一些输出:http://pastebin.com/QCpKSNev.

Here is some output from my latest attempt: http://pastebin.com/QCpKSNev.

问题:

  1. 当从 Linux 主机交叉编译 Qt for Windows 之类的东西时,是否应该调用本机编译器永远?也就是说,在交叉编译过程中,我们不应该使用交叉编译器吗?当我指定 -xplatform 选项时,我不明白为什么 Qt 的配置脚本会尝试调用我系统的本机编译器.

  1. When cross-compiling something like Qt for Windows from a Linux host, should the native compiler ever be invoked? That is, during a cross compilation process, shouldn't we use only the cross compiler? I don't see why Qt's configure script tries to invoke my system's native compiler when I specify the -xplatform option.

如果我使用的是 mingw 交叉编译器,我什么时候需要处理规范文件?GCC 的规范文件对我来说仍然有点神秘,所以我想知道这里的一些背景知识是否对我有帮助.

If I'm using a mingw cross-compiler, when will I have to deal with a specs file? Spec files for GCC are still sort of a mystery to me, so I am wondering if some background here will help me.

一般来说,除了在我的 qmake.conf 中指定交叉编译器之外,我还需要考虑什么?

In general, beyond specifying a cross compiler in my qmake.conf, what else might I need to consider?

推荐答案

只需使用 M 跨环境 (MXE).它消除了整个过程的痛苦:

Just use M cross environment (MXE). It takes the pain out of the whole process:

  • 获取:

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

  • 安装构建依赖项

    为 Windows 构建 Qt、它的依赖项和交叉构建工具;在具有良好互联网访问权限的快速机器上,这将需要大约一个小时;下载大约 500MB:

    Build Qt for Windows, its dependencies, and the cross-build tools; this will take about an hour on a fast machine with decent internet access; the download is about 500MB:

    $ cd mxe && make qt
    

  • 转到您应用的目录并将交叉构建工具添加到 PATH 环境变量:

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

  • 运行 Qt Makefile 生成器工具然后构建:

  • Run the Qt Makefile generator tool then build:

    $ <mxe root>/usr/i686-pc-mingw32/qt/bin/qmake && make
    

  • 您应该在 ./release 目录中找到二进制文件:

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

    $ wine release/foo.exe
    

  • 一些注意事项:

    • 使用MXE仓库的master分支;它似乎得到了开发团队的更多喜爱.

    • Use the master branch of the MXE repository; it appears to get a lot more love from the development team.

    输出是 32 位静态二进制文件,可在 64 位 Windows 上正常运行.

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

    这篇关于如何配置 Qt 以进行从 Linux 到 Windows 目标的交叉编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆