Timeline

2025-11-21

  1. init

Environment

os

Compilation

Compile for aarch64.
Optional: enable -O0, -g3 debug info.

1
2
3
4
5
6
7
8
9
10
11
wget https://download.qemu.org/qemu-10.2.0.tar.xz

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

sudo apt-get install python3.9 python3-pip ninja-build
python3.9 -m pip install --user tomli sphinx sphinx_rtd_theme
# Set environment variables in ~/.bashrc or ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"
# The version installed via apt is too old; qemu-10.2.0 requires 2.66.0+
sudo apt-get install libglib2.0-dev pkg-config

Compile glib:

1
2
3
4
5
6
7
8
9
10
11
12
python3.9 -m pip install --user meson ninja
meson setup _build \
--prefix="$(pwd)/_install" \
--libdir=lib \
--buildtype=release \
-Ddefault_library=shared

# Build
ninja -C _build

# Install
ninja -C _build install

Compile qemu:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Temporarily set environment variables
export PKG_CONFIG_PATH="$HOME/tools/glib-2.72.4/_install/lib/pkgconfig:$PKG_CONFIG_PATH"
# Use rpath to embed library path during compilation
export LD_LIBRARY_PATH="$HOME/tools/glib-2.72.4/_install/lib:$LD_LIBRARY_PATH"

./configure \
--target-list=aarch64-softmmu \
--prefix=$(pwd)/_install \
--python=/usr/bin/python3.9 \
--extra-ldflags="-Wl,-rpath,$HOME/tools/glib-2.72.4/_install/lib"

# optional: enable -O0, -g3 debug info
./configure \
--target-list=aarch64-softmmu \
--prefix=$(pwd)/_install \
--python=/usr/bin/python3.9 \
--extra-ldflags="-Wl,-rpath,$HOME/tools/glib-2.72.4/_install/lib" \
--extra-cflags="-O0 -g3"

make -j$(nproc)
make install

# After compilation, verify: should output RUNPATH /home/zhaohang/tools/glib-2.72.4/_install/lib
objdump -p _install/bin/qemu-system-aarch64 | grep RUNPATH

# Recommended: set environment variable in ~/.bashrc or ~/.zshrc
export PATH="$HOME/tools/qemu-10.2.0/bin:$PATH"

compile_commands.json

Compilation automatically generates compile_commands.json:

1
cp build/compile_commands.json .

GDB Debugging

There is a .gdbinit in the qemu directory. Running gdb in this directory automatically executes the scripts/qemu-gdb.py script. For specific debugging methods, refer to:

For GDB usage, refer to: