How to compile QEMU on Win64

Tutorials for Operating Systems, Applications etc can be posted here.
Post Reply
TheCollector1988
User avatar
Donator
Posts: 3549
Joined: Wed Feb 23, 2011 12:11 am
Location: Italy
Contact:

How to compile QEMU on Win64

Post by TheCollector1988 »

Since the following site URL http://virtuallyfun.superglobalmegacorp.com/?p=3092 no longer provides newer versions of QEMU for Win32 (such as 1.5.x), I decided to put my own guide here (if it's on-topic)

First major step: prepare the MinGW 64-bit environment for the dependency components of QEMU
Requirements
Get the MinGW-w64 package from here:
http://mingw-w64.sourceforge.net/downlo ... ngw-builds
And check the downloads, and, in the installer of MinGW 64-bit, use the sjsj exception, use gcc 4.8.1, and win32 thread and rev1.
However, this does not install MSYS by default, so you need to get it separately, from here: http://sourceforge.net/projects/mingw-w ... 32-bit%29/

Install Python 2.7 from here:
http://www.python.org/download/releases/2.7/
Accept the default directory it gives (C:\Python27).
After being installed, make a copy of python.exe as python2.5.exe.

Once gotten, we can start compiling the dependencies.

1)
Get the latest release of libffi from here:
http://www.mirrorservice.org/sites/sour ... ub/libffi/
compile it with:

Code: Select all

./configure --prefix=/c/mingw-builds/mingw64 --build=x86_64-w64-mingw32
make
make install
2)
Get libiconv-1.14 from here:
http://ftp.gnu.org/pub/gnu/libiconv/lib ... .14.tar.gz
compile it with:

Code: Select all

./configure --prefix=/c/mingw-builds/mingw64 --build=x86_64-w64-mingw32
make
make install
3)
Get the latest release of gettext from here:
http://ftp.gnu.org/gnu/gettext/
compile it with the following options:

Code: Select all

./configure --prefix=/c/mingw-builds/mingw64 --enable-threads=win32 --enable-relocatable --build=x86_64-w64-mingw32
make
make install
Watch out! You need to use these in the shell of MSYS every time you need to compile Glib and Qemu:

Code: Select all

PATH=/c/Python27:/c/Python27/DLLs:$PATH
export PATH
4)
Watch out again! As explained in the official Qemu website, Glib 2.23 and higher in x64 mode won't make Qemu work!.
Get glib for win64 here (x64):
http://www.gtk.org/download/win64.php (grab the sources instead of the dev and bin)
compile it first with:

Code: Select all

export LIBFFI_CFLAGS='-I /c/mingw-builds/mingw64/lib/libffi-3.0.13/include'
export LIBFFI_LIBS=-lffi
export lt_cv_deplibs_check_method="pass_all"
export CFLAGS="-O0 -g -pipe -Wall -mms-bitfields -mthreads"
export CPPFLAGS="-DG_ATOMIC_OP_USE_GCC_BUILTINS=1"
configure -prefix=/c/mingw-builds/mingw64 -with-pcre=internal -disable-static -disable-gtk-doc -enable-silent-rules -build=x86_64-w64-mingw32
make
make install
Fixes for the glib compile failures about libintl.h: Glib can't find the right path to libintl.h, so you need to copy it to the glib-2.26.1 directory and modify configure (the file), search "libintl.h" (with quotes) and replace it with your path of the include directory containing libintl.h (in this case: c:/mingw-builds/mingw64/include/libintl.h)

5)
Grab pkg-config from here:
http://pkgconfig.freedesktop.org/releases/
compile it with:

Code: Select all

export GLIB_CFLAGS="-I /c/mingw-builds/mingw64/include/glib-2.0 -I /c/mingw-builds/mingw64/lib/glib-2.0/include"
export GLIB_LIBS="-lglib-2.0"
configure -prefix=/c/mingw-builds/mingw64 -build=x86_64-w64-mingw32
make
make install
6)
Rebuild Glib with these options instead:

Code: Select all

configure -prefix=/c/mingw-builds/mingw64 -build=x86_64-w64-mingw32
make
make install
7)
Grab SDL from here:
http://www.libsdl.org/download-1.2.php (Select the mingw32 one)
compile it with:

Code: Select all

configure -prefix=/c/mingw-builds/mingw64 -build=x86_64-w64-mingw32
make
make install
8) (Optional for QEMU versions prior to 1.3)
Grab pixman from here:
http://pkgs.fedoraproject.org/repo/pkgs ... 0a9a15f20/
compile it with:

Code: Select all

configure -prefix=/c/mingw-builds/mingw64 -build=x86_64-w64-mingw32
make
make install
Second and last step, compiling QEMU!
If you want to compile QEMU 1.x, you need to put, every time, the python path to the MSYS shell that is shown above in this tutorial.

Grab the latest git release here:
http://wiki.qemu.org/Main_Page

and start compiling with:

Code: Select all

./configure
make
make install
If anyone's having problems starting QEMU, let me know so I can change this guide.
Last edited by TheCollector1988 on Mon Jul 08, 2013 10:44 pm, edited 4 times in total.

Wheatley
User avatar
Donator
Posts: 1839
Joined: Thu Oct 25, 2012 8:19 pm
Location: shell32.dll

Re: How to compile QEMU on Win64

Post by Wheatley »

Thank you for this easy to understand guide :)
Windows Defender for great justice! Bugs are an international trading company. I need to defeat the anti-debugging and obfuscation methods. It wasn't for Intel's absurd ability to load in ie6. Why even waste time with people in an envelope?

therock247uk
Donator
Posts: 148
Joined: Sun Feb 11, 2007 4:48 pm
Location: UK
Contact:

Re: How to compile QEMU on Win64

Post by therock247uk »

very very nice!!

Terra854
User avatar
FTP Access
Posts: 555
Joined: Tue Oct 04, 2011 5:57 am
Location: Singapore

Re: How to compile QEMU on Win64

Post by Terra854 »

Do we run the commands using bash?

Wheatley
User avatar
Donator
Posts: 1839
Joined: Thu Oct 25, 2012 8:19 pm
Location: shell32.dll

Re: How to compile QEMU on Win64

Post by Wheatley »

Terra854 wrote:Do we run the commands using bash?
Yes, everything related to MinGW is done in bash.
Windows Defender for great justice! Bugs are an international trading company. I need to defeat the anti-debugging and obfuscation methods. It wasn't for Intel's absurd ability to load in ie6. Why even waste time with people in an envelope?

raidenii
FTP Access
Posts: 25
Joined: Tue Jun 29, 2010 4:47 am
Location: /dev/null

Re: How to compile QEMU on Win64

Post by raidenii »

Thanks for the guide, also the Cirrus patch seems still having some major problems with Windows 3.1...

TheCollector1988
User avatar
Donator
Posts: 3549
Joined: Wed Feb 23, 2011 12:11 am
Location: Italy
Contact:

Re: How to compile QEMU on Win64

Post by TheCollector1988 »

raidenii wrote:Thanks for the guide, also the Cirrus patch seems still having some major problems with Windows 3.1...
I fixed that with an old patch (it was originally for 0.11, from 2009/2010) that was posted on a Japanese website, I might provide it someday but it will need to be edited to be compatible with 1.5 or 1.6.

raidenii
FTP Access
Posts: 25
Joined: Tue Jun 29, 2010 4:47 am
Location: /dev/null

Re: How to compile QEMU on Win64

Post by raidenii »

TheCollector1988 wrote:
raidenii wrote:Thanks for the guide, also the Cirrus patch seems still having some major problems with Windows 3.1...
I fixed that with an old patch (it was originally for 0.11, from 2009/2010) that was posted on a Japanese website, I might provide it someday but it will need to be edited to be compatible with 1.5 or 1.6.
I believe you got it from here?
http://bauxite.sakura.ne.jp/software/qemu/

TheCollector1988
User avatar
Donator
Posts: 3549
Joined: Wed Feb 23, 2011 12:11 am
Location: Italy
Contact:

Re: How to compile QEMU on Win64

Post by TheCollector1988 »

raidenii wrote:
TheCollector1988 wrote:
raidenii wrote:Thanks for the guide, also the Cirrus patch seems still having some major problems with Windows 3.1...
I fixed that with an old patch (it was originally for 0.11, from 2009/2010) that was posted on a Japanese website, I might provide it someday but it will need to be edited to be compatible with 1.5 or 1.6.
I believe you got it from here?
http://bauxite.sakura.ne.jp/software/qemu/
yep, I got it from there.

therock247uk
Donator
Posts: 148
Joined: Sun Feb 11, 2007 4:48 pm
Location: UK
Contact:

Re: How to compile QEMU on Win64

Post by therock247uk »

hmm im trying to build a new environment got everything compiled and happy but on doing ./configure for qemu i get...

ERROR: "cc" either does not exist or does not work

louisw3
User avatar
FTP Access
Posts: 1462
Joined: Wed Dec 31, 2008 7:29 pm
Location: SE Asia

Re: How to compile QEMU on Win64

Post by louisw3 »

therock247uk wrote:hmm im trying to build a new environment got everything compiled and happy but on doing ./configure for qemu i get...

ERROR: "cc" either does not exist or does not work

Code: Select all

export CC=gcc
Although I'm not having much luck with the resulting binary.... and I still have glib2 issues..... :|

I never was that good at debugging this stuff.

Code: Select all

$ gdb i386-softmmu/qemu-system-i386
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from C:\msys\home\User\qemu-1.6.2\i386-softmmu\qemu-system-i386
.exe...done.
(gdb) set args -L pc-bios -m 16
(gdb) r
Starting program: C:\msys\home\User\qemu-1.6.2/i386-softmmu/qemu-system-i386.ex
e -L pc-bios -m 16
[New Thread 4040.0x14c]
[New Thread 4040.0xf10]
[New Thread 4040.0xaa0]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 4040.0xf10]
0x0000000077155371 in ntdll!RtlUnwindEx () from C:\Windows\system32\ntdll.dll
(gdb) t 1
[Switching to thread 1 (Thread 4040.0x14c)]
#0  0x000000007719046a in ntdll!ZwWaitForMultipleObjects ()
   from C:\Windows\system32\ntdll.dll
(gdb) bt
#0  0x000000007719046a in ntdll!ZwWaitForMultipleObjects ()
   from C:\Windows\system32\ntdll.dll
#1  0x000007fefd3813a6 in KERNELBASE!GetCurrentThread ()
   from C:\Windows\system32\KernelBase.dll
#2  0x0000000000000002 in ?? ()
#3  0x0000000000000001 in ?? ()
#4  0x0000000000226fb8 in ?? ()
#5  0x000007fefd3844a6 in SetThreadLocale ()
   from C:\Windows\system32\KernelBase.dll
#6  0x0000000000226fb8 in ?? ()
#7  0x0000000000000000 in ?? ()
(gdb) t 2
[Switching to thread 2 (Thread 4040.0xf10)]
#0  0x0000000077155371 in ntdll!RtlUnwindEx ()
   from C:\Windows\system32\ntdll.dll
(gdb) bt
#0  0x0000000077155371 in ntdll!RtlUnwindEx ()
   from C:\Windows\system32\ntdll.dll
#1  0x0000000004a00000 in ?? ()
#2  0x00000000049ff490 in ?? ()
#3  0x000000000001b84c in ?? ()
#4  0x0000000050000163 in ?? ()
#5  0x000000000000007f in ?? ()
#6  0x00000000003ca200 in ?? ()
#7  0x0000000000000000 in ?? ()
(gdb) t 3
[Switching to thread 3 (Thread 4040.0xaa0)]
#0  0x000000007719046a in ntdll!ZwWaitForMultipleObjects ()
   from C:\Windows\system32\ntdll.dll
(gdb) bt
#0  0x000000007719046a in ntdll!ZwWaitForMultipleObjects ()
   from C:\Windows\system32\ntdll.dll
#1  0x000007fefae3a8af in timeEndPeriod () from C:\Windows\system32\winmm.dll
#2  0x00000000006bc860 in chardevs ()
#3  0x00000000000000a0 in ?? ()
#4  0x000007fefae60400 in waveOutGetID () from C:\Windows\system32\winmm.dll
#5  0x0000000000000000 in ?? ()
(gdb) t 4
waveOutGetID ... I think is causing my crash. Not sure thought. I've also switched to rebuilding with -O1 flags instead of -O2, as I know that used to annoy the win32 build of Qemu in coroutines-win32.c ... But I get the same crash.

I guess all that is left is to try forcing SDL audio "--audio-drv-list=sdl" or switching to the new/slower backend "--enable-tcg-interpreter"
"Those who don't understand UNIX are condemned to reinvent it, poorly." – Henry Spencer

TheCollector1988
User avatar
Donator
Posts: 3549
Joined: Wed Feb 23, 2011 12:11 am
Location: Italy
Contact:

Re: How to compile QEMU on Win64

Post by TheCollector1988 »

use -O0 for no optimizations

louisw3
User avatar
FTP Access
Posts: 1462
Joined: Wed Dec 31, 2008 7:29 pm
Location: SE Asia

Re: How to compile QEMU on Win64

Post by louisw3 »

TheCollector1988 wrote:use -O0 for no optimizations
what versions are you using? gcc? glib2?

I'm going to trash all my stuff and rebuild... qemu & glib as O0 and see how that goes.
"Those who don't understand UNIX are condemned to reinvent it, poorly." – Henry Spencer

TheCollector1988
User avatar
Donator
Posts: 3549
Joined: Wed Feb 23, 2011 12:11 am
Location: Italy
Contact:

Re: How to compile QEMU on Win64

Post by TheCollector1988 »

louisw3 wrote:
TheCollector1988 wrote:use -O0 for no optimizations
what versions are you using? gcc? glib2?

I'm going to trash all my stuff and rebuild... qemu & glib as O0 and see how that goes.
gcc 4.8.1 and glib 2.39.0 with MinGW (not MinGW-builds)

louisw3
User avatar
FTP Access
Posts: 1462
Joined: Wed Dec 31, 2008 7:29 pm
Location: SE Asia

Re: How to compile QEMU on Win64

Post by louisw3 »

TheCollector1988 wrote:
louisw3 wrote:
TheCollector1988 wrote:use -O0 for no optimizations
what versions are you using? gcc? glib2?

I'm going to trash all my stuff and rebuild... qemu & glib as O0 and see how that goes.
gcc 4.8.1 and glib 2.39.0 with MinGW (not MinGW-builds)
Ok I'll try those... on the rebuild glib phase I get a bunch of undefined crap... and of course if it does work, it'll just fail as un spectacularly as always...

can you build qemu 1.7.0? I'm trying a bunch of versions, but as always a known working thing is so much easier to start with before deviating.
"Those who don't understand UNIX are condemned to reinvent it, poorly." – Henry Spencer

DJ Deedahx
User avatar
FTP Access
Posts: 479
Joined: Sun Sep 08, 2013 8:56 pm

Re: How to compile QEMU on Win64

Post by DJ Deedahx »

Thanks for this tutorial. I will surely refer to it when I get to download QEMU.

But, really, couldn't they have a separate EXE for noobs?
86Box Staff/Power User & YouTube Channel Manager
Now known as DDX(official) on most places on the Internet.

gustopher
Posts: 5
Joined: Mon Nov 11, 2013 11:59 pm

Re: How to compile QEMU on Win64

Post by gustopher »

DJ Deedahx wrote:Thanks for this tutorial. I will surely refer to it when I get to download QEMU.

But, really, couldn't they have a separate EXE for noobs?
Isn't this what you're looking for? http://qemu.weilnetz.de/w64/

Post Reply