Hosts/W32: Difference between revisions

From QEMU
Line 180: Line 180:
=== Native builds with Cygwin ===
=== Native builds with Cygwin ===


Builds with the normal Cygwin compiler are not supported.
Builds with the normal Cygwin compiler are not supported. Nevertheless, cygwin can be used as a build environment because it also contains all necessary Mingw-w64 packages.
For 32 bit builds, these packages should be installed:


Nevertheless, cygwin can be used as a build environment because it also contains all necessary Mingw-w64 packages.
==== Required packages ====
* mingw64-i686-pixman
* mingw64-i686-pkg-config
* mingw64-i686-gcc-g++
 
==== Recommended packages ====
* Tbd.
 
==== Optional packages ====
* Tbd.


== Building QEMU for W64 ==
== Building QEMU for W64 ==

Revision as of 09:39, 25 August 2016

QEMU on W32 and W64 hosts

This documentation is work in progress - more information will be added as needed. It will finally replace the old documentation from the QEMU user manual. I think that a wiki is better in keeping evolving documentation like this one up to date.

While QEMU's main host platform is Linux, it is sometimes also useful to build or run it on members of the W32 / W64 family of operating systems (MS Windows 2000, Windows XP, Windows Vista, Windows 7, ...) or on ReactOS (a W32 clone).

Running QEMU on the 64-bit variants is similar but needs additional documentation and currently some code patches. Support for W64 was added in QEMU 1.1.

Please note that less developers work on QEMU for W32 / W64 hosts, so it might be less stable (but I don't think it is).

Some system emulations on Linux use KVM, a special emulation mode which claims to reach nearly native speed. KVM is mainly used for x86 (32 and 64 bit) emulation on x86 hosts running Linux. There exists a highly experimental KVM for W32, but it is unknown whether it works with QEMU.

Building QEMU for W32

QEMU for W32 needs a fairly complete Mingw-w64 based development environment with tools (make, compiler, linker, ...) and some additional libraries. Building with the older MinGW does not work!

Cross builds

Compilation of QEMU for W32 on non-W32 hosts (e.g. Linux hosts) is called cross compilation. Some Linux distributions (Debian, Ubuntu, Fedora and maybe others) already include packages needed for cross compilation, so the installation of these packages is the first step.

Debian based cross builds

# Debian squeeze for W32:
apt-get install gcc-mingw32 mingw32-binutils mingw32-runtime
# Debian (squeeze?) for W64:
apt-get install gcc-mingw32 mingw32-binutils mingw-w64

SDL support is not included in standard MinGW, but packages for MinGW are available on the SDL homepage. POSIX thread support is not included in Debian or Ubuntu. Latest QEMU will need it, so you have to get it from MinGW (see links below).

Cross compilers usually are installed in /usr/bin with a prefix. For Debian, the cross gcc is called i586-mingw32msvc-gcc. This cross prefix must be passed to QEMU's configure.

# Debian cross configuration for W32:
configure --cross-prefix=i586-mingw32msvc- [--extra-cflags=-mthreads]

Compiler option is needed for gcc versions which don't support TLS (thread local storage) without it (version 4.4 which is Debian's default needs it!).

Debian does not include a cross pkg-config, but it is required for cross builds. The following script can be saved as /usr/bin/i586-mingw32msvc-pkg-config and optionally be linked to /usr/bin/amd64-mingw32msvc-pkg-config.

#!/bin/sh
basename=`basename $0`
prefix=/usr/`echo $basename|sed s/-pkg-config//`
PKG_CONFIG_LIBDIR=$prefix/lib/pkgconfig
export PKG_CONFIG_LIBDIR
pkg-config --define-variable=prefix=$prefix $@

Linux Mint based cross builds

These instructions were tested with the Linux Mint Debian Edition on 2012-06-02.

# Linux Mint for W32 and W64 (about 463 MiB):
apt-get install mingw-w64

OpenSUSE based cross builds

Add http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_11.4 (update with your release version) to the list of software repositories. Then install at least the following packets (most of them are pulled via dependencies):

mingw32-binutils
mingw32-cpp
mingw32-cross-binutils
mingw32-cross-cpp
mingw32-cross-gcc
mingw32-cross-pkg-config
mingw32-filesystem
mingw32-gcc
mingw32-glib2
mingw32-glib2-devel
mingw32-glib2-lang
mingw32-headers
mingw32-libgcc
mingw32-libgmp
mingw32-libintl
mingw32-libintl-devel
mingw32-libmpc
mingw32-libmpfr
mingw32-libSDL
mingw32-libSDL-devel
mingw32-libssp
mingw32-runtime
mingw32-zlib
mingw32-zlib-devel

This toolchain does not include libiberty.a in its binutils package, but it also does not need to. If building against a QEMU version that still pulls this in unconditionally, simply drop the -liberty from configure.

For W64 use the corresponding win64 repository and mingw64- packages.

Fedora based cross builds

Fedora supports both W64 and W32 cross builds. The following instructions were tested on F17:

# Fedora for W32 cross build:
yum install mingw32-pixman
yum install mingw32-glib2
yum install mingw32-gmp
yum install mingw32-SDL
yum install mingw32-pkg-config
# Fedora for W64 cross build:
yum install mingw64-pixman
yum install mingw64-glib2
yum install mingw64-gmp
yum install mingw64-SDL
yum install mingw64-pkg-config

Cross compilers usually are installed in /usr/bin with a prefix. This cross prefix must be passed to QEMU's configure. The prefix depends on your target platform.

For Fedora W64 builds, the cross gcc is called x86_64-w64-mingw32-gcc.

# Fedora cross configuration for W64:
./configure --cross-prefix=x86_64-w64-mingw32-

For Fedora W32 builds, it depends on Fedora version. For Fedora 17, the cross gcc is called i686-w32-mingw32-gcc.

# Fedora 17 cross configuration for W32:
./configure --cross-prefix=i686-w32-mingw32-

For Fedora 18 and later, the cross gcc is called i686-w64-mingw32-gcc.

# Fedora 18 and later cross configuration for W32:
./configure --cross-prefix=i686-w64-mingw32-

Note that "-mingw32-" (and for Fedora 18 and later, w64) appears in prefix for both W32 and W64 builds.

Docker based cross builds

As of June 2016, the master tree supports "docker based compiling", which can be used for convenient windows cross build.

Make sure your docker command works ("docker ps" or "sudo docker ps" reports no error), then cd into the root of QEMU source tree and run

make docker-test-mingw@fedora V=1 DEBUG=1 J=4

, it will download and initialize the needed docker image for you, and drop you into a shell in the started container. Run

cd $QEMU_SRC

then

./configure --cross-prefix=x86_64-w64-mingw32-

or

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

for 64bit/32bit builds respectively.

Native builds with Mingw-w64

Get and install Mingw-w64. In addition, some more packages are needed:

Libraries (also needed for cross builds)

Tools (only needed for native builds)

Get the QEMU source code (git or tarball), then run configure and make.

Native builds with Cygwin

Builds with the normal Cygwin compiler are not supported. Nevertheless, cygwin can be used as a build environment because it also contains all necessary Mingw-w64 packages. For 32 bit builds, these packages should be installed:

Required packages

  • mingw64-i686-pixman
  • mingw64-i686-pkg-config
  • mingw64-i686-gcc-g++

Recommended packages

  • Tbd.

Optional packages

  • Tbd.

Building QEMU for W64

QEMU for W64 needs a fairly complete MinGW-w64 based development environment with tools (make, compiler, linker, ...) and some additional libraries.

Cross builds

Compilation of QEMU for W64 on non-W64 hosts (e.g. Linux hosts) is called cross compilation. Some Linux distributions (Debian, Ubuntu, Fedora and maybe others) already include packages needed for cross compilation, so the installation of these packages is the first step.

Debian based cross builds

# Debian cross configuration for W64:
configure --cross-prefix=amd64-mingw32msvc-

Fedora based cross builds

# Fedora cross configuration for W64:
./configure --cross-prefix=x86_64-w64-mingw32-

Libraries (also needed for cross builds)

Installation

Installation is easy with the experimental installers from qemu.weilnetz.de.

Running QEMU for W32

User mode emulation is unsupported: it only works on BSD, Darwin and Linux.

System emulation

All QEMU system emulation should be working (that simply means I don't know of emulations which don't work, and those which I tried, namely x86 and mips, work well).

Special W32 devices

QEMU is based on Mingw-w64, so some commonly used UNIX device names like /dev/null or /dev/zero can be used. W32 device names also work, especially names like //./PhysicalDrive0 for the first hard disk of the host (this name must be used with extreme care or you will likely crash your system).

Text which is normally printed by QEMU to the console output channels (normally known as standard output = stdout and standard error output = stderr) might be written to files called stdout.txt and stderr.txt. If you want to see QEMU's help messages or if it does not work as expected, you should look for these files in the directory where your exe file is installed.

Links

MinGW Website (old, no longer supported by QEMU)
http://www.mingw.org/
Mingw-w64 Website (supports both 32 and 64 bit builds)
http://mingw-w64.sourceforge.net/
GLib-2.0 for MinGW
http://www.gtk.org/download/win32.php
http://www.gtk.org/download/win64.php
POSIX thread support for MinGW (old, no longer needed)
http://sourceforge.net/projects/mingw/files/MinGW/pthreads-w32/
libSDL 1.2 for MinGW (old, no longer needed)
http://www.libsdl.org/download-1.2.php