[英]How do I invoke the MinGW cross-compiler on Linux?
I have a project that I want to cross-compile for Windows.我有一个要为 Windows 交叉编译的项目。 I have the appropriate Makefile and everything works with
g++
.我有适当的 Makefile 并且一切都适用于
g++
。 I've run我跑了
$ apt install mingw-w64
and downloaded 500 MB of packages, but I cannot find out how to actually run it.并下载了 500 MB 的软件包,但我不知道如何实际运行它。 There is no
mingw
executable, so how do I actually compile with it?没有
mingw
可执行文件,那么我该如何实际编译呢?
If you look at the file lists on the Ubuntu package webserver for mingw-w64
's constituent packages:如果您查看
mingw-w64
组成软件包的 Ubuntu 软件包网络服务器上的文件列表:
gcc-mingw-w64-x86-64
g++-mingw-w64-x86-64
binutils-mingw-w64-x86-64
mingw-w64-x86-64-dev
gcc-mingw-w64-i686
g++-mingw-w64-i686
binutils-mingw-w64-i686
mingw-w64-i686-dev
You can see that mingw-w64
provides a toolchain , ie a set of alternative tools (compiler, linker, headers, etc.) used to compile your code for another system.您可以看到
mingw-w64
提供了一个工具链,即一组用于为另一个系统编译您的代码的替代工具(编译器、链接器、头文件等)。
Assuming you want to compile C++ code for a 64-bit system, you'll need to use /usr/bin/x86_64-w64-mingw32-g++-win32
.假设您要为 64 位系统编译 C++ 代码,则需要使用
/usr/bin/x86_64-w64-mingw32-g++-win32
。 You can use the CXX
environment variable to tell most Makefiles to use that compiler to compile code.您可以使用
CXX
环境变量来告诉大多数 Makefile 使用该编译器来编译代码。
Another option is to take a look at Mingw Cross Environment ( MXE ), which is specifically targetting at cross compiling from Linux to Windows (and lately also to Mac).另一种选择是查看 Mingw Cross Environment ( MXE ),它专门针对从 Linux 到 Windows(最近也到 Mac)的交叉编译。 The package has bult-in xupport for a large number of libraries and is actively being developed.
该软件包具有用于大量库的内置 xupport,并且正在积极开发中。 Just take a look at the website to find out if it suits your needs.
只需查看该网站,看看它是否适合您的需求。
By the way,it is suggested you use the development rather than the release version.顺便说一句,建议您使用开发版而不是发行版。 This is because release versions are generally outdated very fast, due to package maintainers (of the libraries) changing URLs resulting in the MXE release version becoming broken.
这是因为发布版本通常很快就会过时,这是由于(库的)包维护者更改 URL 导致 MXE 发布版本损坏。 The development version is generally more up-to-date.
开发版本通常是最新的。
I used this to cross compile postgres:我用它来交叉编译 postgres:
$ sudo apt-get install mingw-w64
$ ./configure --host=i686-w64-mingw32 --without-zlib # 32 bit
# or --host=x86_64-w64-mingw32 64 bit
Other projects do it differently, like ffmpeg:其他项目的做法不同,比如 ffmpeg:
./configure --target-os=mingw32 --cross-prefix=i686-w64-mingw32-
or some或一些
./configure CC=i686-w64-mingw32-gcc ...
etc. GL!等等。GL!
这是我如何定位mingw g++
交叉编译器:
$ ./configure --with-mingw-cross-compiler=g++-mingw-w64-i686
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.