简体   繁体   中英

How do I invoke the MinGW cross-compiler on Linux?

I have a project that I want to cross-compile for Windows. I have the appropriate Makefile and everything works with g++ . I've run

$ apt install mingw-w64

and downloaded 500 MB of packages, but I cannot find out how to actually run it. There is no mingw executable, so how do I actually compile with it?

If you look at the file lists on the Ubuntu package webserver for mingw-w64 's constituent packages:

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.

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 . You can use the CXX environment variable to tell most Makefiles to use that compiler to compile code.

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). The package has bult-in xupport for a large number of libraries and is actively being developed. 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. The development version is generally more up-to-date.

I used this to cross compile postgres:

$ sudo apt-get install mingw-w64
$ ./configure --host=i686-w64-mingw32 --without-zlib #  32 bit
# or --host=x86_64-w64-mingw32  64 bit

ref here

Other projects do it differently, like ffmpeg:

 ./configure --target-os=mingw32 --cross-prefix=i686-w64-mingw32-

or some

  ./configure CC=i686-w64-mingw32-gcc ...

etc. GL!

这是我如何定位mingw g++交叉编译器:

$ ./configure --with-mingw-cross-compiler=g++-mingw-w64-i686

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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