MinGW

Jump to: navigation, search

The openSUSE distributions Leap and Tumbleweed offer the mingw-w64 toolchain for cross-compilation to Windows environments. Benefits are faster build times (presumably faster process creation, faster filesystems and generally less overhead in syscalls.) If WINE is available, such binaries can even be run from the Linux environment afterwards.

Naming

Packages are generally called mingw64-* for Windows x64 and mingw32-* for Windows x86 targets, respectively. Cross-compilation to Windows x64 is available from all architectures including non-x86 — that is the whole point of cross-compilation. [If there is ever going to be a time when compilation for Windows ARM (32 or 64) is offered, new unique prefixes will need to be added that do not conflict with mingw64-.]

The GNU build triplets are x86_64-w64-mingw32 and i686-w64-mingw32 (CPU-VENDOR-OS) for x64 and x86, respectively. The vendor string is seldomly if ever evaluated. The OS string is just a fixed string and gives a rough idea of the semantics and available set of programs (the 32 does not mean anything in particular). Cygwin for example uses x86_64-pc-cygwin.

Compiler

Installation of the cross-compiling toolchain, e.g.:

zypper in mingw64-cross-gcc-c++ mingw64-cross-pkgconf

With this, the obligatory Hello World rundown:

$ echo -en '#include <cstdio>\n' 'int main() { printf("Hello world\\n"); }' >x.cpp
$ x86_64-w64-mingw32-g++ x.cpp
$ wine ./a.exe
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:wineusb:query_id Unhandled ID query type 0x5.
Hello world

The build triplet comes handy for any software using autoconf, which will automatically find cross toolchains:

$ ./configure --host=x86_64-w64-mingw32
configure: loading site script /usr/share/site/x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for x86_64-w64-mingw32-strip... x86_64-w64-mingw32-strip
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to create a pax tar archive... gnutar
checking whether make supports nested variables... (cached) yes
checking for x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
…

Take note that the cross compiler is in mingw64-cross-gcc (runs on Linux, produces for Windows); the mingw64-gcc package on the other hand is a native compiler (in other words, runs on Windows/WINE and produces for Windows).

Additional packages

In the base distributions (Leap, Tumbleweed), only the bare minimum toolchain is included to build the openSUSE launcher for WSL and possibly some EFI executables. A plethora of libraries and graphical toolkits is offered in the extra repositories windows:mingw:win64 and windows:mingw:win32. Installation e.g.:

# zypper ar obs://windows:mingw:win64 mingw64
# zypper in mingw64-wxWidgets-3_2-devel

Using WINE for test launches

The default search path of WINE includes just e.g. /usr/lib64/wine/x86_64-windows. This is enough to satisfy the "Hello World" example above which only depends on kernel32.dll and msvcrt.dll (both provided by WINE), but additional libraries need to be copied or symlinked into the directory of the executable, e.g.:

# zypper in mingw64-xxhash-devel
$ echo -en '#include <xxhash.h>\n' 'int main() { return XXH_versionNumber(); }' >x.cpp
$ x86_64-w64-mingw32-g++ x.cpp -lxxhash
$ wine a.exe
<other WINE warnings…>
00dc:err:module:import_dll Library libxxhash.dll (which is needed by L"Z:\\tmp\\a.exe") not found
00dc:err:module:loader_init Importing dlls for L"Z:\\tmp\\a.exe" failed, status c0000135
$ ln -s /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libxxhash.dll .
$ wine a.exe
<WINE warnings…>
(No other output, and success)