Cover image for Qemu Compilation

Qemu Compilation

Words 402
Views
Visitors
Timeline

Timeline

2025-11-21

  1. init
This article describes the Qemu compilation process, including preparation of the compilation environment, compilation methods for the aarch64 architecture, optionally enabling O0 and -g3 debug information, steps for compiling glib and qemu, and the operation of automatically generating compile_commands.json during compilation. Finally, it explains how to use the .gdbinit in the QEMU source directory for gdb debugging.

Environment

os
os

Compilation

Compile aarch64

Optional: Enable O0, -g3 debug information

1234567891011
wget https://download.qemu.org/qemu-10.2.0.tar.xzsudo add-apt-repository ppa:deadsnakes/ppasudo apt-get updatesudo apt-get install python3.9 python3-pip ninja-buildpython3.9 -m pip install --user tomli sphinx sphinx_rtd_theme# Set environment variables in ~/.bashrc or ~/.zshrcexport PATH="$HOME/.local/bin:$PATH"# The glib version installed via apt is too old, while qemu-10.2.0 requires 2.66.0 or higher.sudo apt-get install libglib2.0-dev pkg-config

Compile glib

123456789101112
python3.9 -m pip install --user meson ninjameson setup _build \    --prefix="$(pwd)/_install" \    --libdir=lib \    --buildtype=release \    -Ddefault_library=shared# Compilationninja -C _build# Installninja -C _build install

Compile qemu

123456789101112131415161718192021222324252627
# Temporarily set environment variablesexport PKG_CONFIG_PATH="$HOME/tools/glib-2.72.4/_install/lib/pkgconfig:$PKG_CONFIG_PATH"# Use rpath to embed the library path when compilingexport 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 information./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, confirm that it should output: RUNPATH /home/zhaohang/tools/glib-2.72.4/_install/libobjdump -p _install/bin/qemu-system-aarch64 | grep RUNPATH# It is recommended to set environment variables in ~/.bashrc or ~/.zshrcexport PATH="$HOME/tools/qemu-10.2.0/bin:$PATH"

compile_commands.json

The compilation will automatically generate compile_commands.json

1
cp build/compile_commands.json .

gdb debugging

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

For gdb usage, refer to:

Loading comments…