xref: /qemu/docs/devel/build-environment.rst (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
1
2.. _setup-build-env:
3
4Setup build environment
5=======================
6
7QEMU uses a lot of dependencies on the host system. glib2 is used everywhere in
8the code base, and most of the other dependencies are optional.
9
10We present here simple instructions to enable native builds on most popular
11systems.
12
13You can find additional instructions on `QEMU wiki <https://wiki.qemu.org/>`_:
14
15- `Linux <https://wiki.qemu.org/Hosts/Linux>`_
16- `MacOS <https://wiki.qemu.org/Hosts/Mac>`_
17- `Windows <https://wiki.qemu.org/Hosts/W32>`_
18- `BSD <https://wiki.qemu.org/Hosts/BSD>`_
19
20Note: Installing dependencies using your package manager build dependencies may
21miss out on deps that have been newly introduced in qemu.git. In more, it misses
22deps the distribution has decided to exclude.
23
24Linux
25-----
26
27Fedora
28++++++
29
30::
31
32    sudo dnf update && sudo dnf builddep qemu
33
34Debian/Ubuntu
35+++++++++++++
36
37You first need to enable `Sources List <https://wiki.debian.org/SourcesList>`_.
38Then, use apt to install dependencies:
39
40::
41
42    sudo apt update && sudo apt build-dep qemu
43
44MacOS
45-----
46
47You first need to install `Homebrew <https://brew.sh/>`_. Then, use it to
48install dependencies:
49
50::
51
52    brew update && brew install $(brew deps --include-build qemu)
53
54Windows
55-------
56
57You first need to install `MSYS2 <https://www.msys2.org/>`_.
58MSYS2 offers `different environments <https://www.msys2.org/docs/environments/>`_.
59x86_64 environments are based on GCC, while aarch64 is based on Clang.
60
61We recommend to use MINGW64 for windows-x86_64 and CLANGARM64 for windows-aarch64
62(only available on windows-aarch64 hosts).
63
64Then, you can open a windows shell, and enter msys2 env using:
65
66::
67
68    c:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64
69    # Replace -ucrt64 by -clangarm64 or -ucrt64 for other environments.
70
71MSYS2 package manager does not offer a built-in way to install build
72dependencies. You can start with this list of packages using pacman:
73
74Note: Dependencies need to be installed again if you use a different MSYS2
75environment.
76
77::
78
79    # update MSYS2 itself, you need to reopen your shell at the end.
80    pacman -Syu
81    pacman -S \
82        base-devel binutils bison diffutils flex git grep make sed \
83        ${MINGW_PACKAGE_PREFIX}-toolchain \
84        ${MINGW_PACKAGE_PREFIX}-glib2 \
85        ${MINGW_PACKAGE_PREFIX}-gtk3 \
86        ${MINGW_PACKAGE_PREFIX}-libnfs \
87        ${MINGW_PACKAGE_PREFIX}-libssh \
88        ${MINGW_PACKAGE_PREFIX}-ninja \
89        ${MINGW_PACKAGE_PREFIX}-pixman \
90        ${MINGW_PACKAGE_PREFIX}-pkgconf \
91        ${MINGW_PACKAGE_PREFIX}-python \
92        ${MINGW_PACKAGE_PREFIX}-SDL2 \
93        ${MINGW_PACKAGE_PREFIX}-zstd
94
95If you want to install all dependencies, it's possible to use recipe used to
96build QEMU in MSYS2 itself.
97
98::
99
100    pacman -S wget
101    wget https://raw.githubusercontent.com/msys2/MINGW-packages/refs/heads/master/mingw-w64-qemu/PKGBUILD
102    # Some packages may be missing for your environment, installation will still
103    # be done though.
104    makepkg -s PKGBUILD || true
105
106Build on windows-aarch64
107++++++++++++++++++++++++
108
109When trying to cross compile meson for x86_64 using UCRT64 or MINGW64 env,
110configure will run into an error because the cpu detected is not correct.
111
112Meson detects x86_64 processes emulated, so you need to manually set the cpu,
113and force a cross compilation (with empty prefix).
114
115::
116
117    ./configure --cpu=x86_64 --cross-prefix=
118
119