如何配置Qt以便从Linux到Windows目标进行交叉编译? [英] How do I configure Qt for cross-compilation from Linux to Windows target?
问题描述
我想使用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.
问题:
-
从Linux主机交叉编译Windows的Qt之类的东西时,应调用本机编译器 ever 吗?也就是说,在交叉编译过程中,我们不应该仅使用 交叉编译器吗?我看不到为什么在指定
-xplatform
选项时Qt的configure脚本会尝试调用系统的本机编译器.
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交叉编译器,什么时候需要处理specs文件? 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?
推荐答案
只需使用跨环境(MXE).它消除了整个过程的痛苦:
Just use M cross environment (MXE). It takes the pain out of the whole process:
-
获取它:
Get it:
$ 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 环境变量:
Go to the directory of your app and add the cross-build tools to the PATH environment variable:
$ 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屋!