一、编译
To download and build QEMU 8.0.2:
wget https://download.qemu.org/qemu-8.0.2.tar.xz tar xJf qemu-8.0.2.tar.xz cd qemu-8.0.2 mkdir build && cd build ../configure make
To download and build QEMU from git:
git clone https://gitlab.com/qemu-project/qemu.git cd qemu git submodule init git submodule update --recursive ./configure make
若仅仅是调试,可不install到机器中,在make后直接以全路径就可以运行qemu,一般都是编译目录下的build/bin/qemu-system-xxx
make install安装后的路径一般是/usr/local/bin,有些以rpm安装的路径一般是/usr/bin。具体优先运行那个elf程序可 echo PATH查看优先级。
二、问题
x86架构下手动搭建qemu编译环境总是缺少包,记录下以备以后:
Q1:ERROR: Cannot find Ninja
A1:rpm -ivh ninja-1.8.2-lp151.2.5.x86_64.rpm
Q2:ERROR: glib-2.56 gthread-2.0 is required to compile QEMU
A2: yum -y install glib2 glib2-devel
Q3:ERROR: Dependency "pixman-1" not found, tried pkgconfig
A3:yum install pixman pixman-devel
三、其它编译选项
如果涉及到对文件大小有要求,可以选择取消编入debug信息,主要是在configure里配置:
# configure --disable-debug-info
# make -j `nproc`
可以对比不带debug信息的文件从100M--》25M
其余选项可以configure --help查询
# cd build
# ../configure --target-list=ppc64-softmmu --disable-debug-info --enable-kvm --enable-rng-none
三、静态编译
静态编译只需要在configure时添加--static选项即可,如
../configure --target-list=arm-softmmu --static
# --target-list 选择你想安装的架构,默认全部安装。这里”xxx-softmmu”和”xxx-linux-user”分别指系统模拟器和应用程序模拟器, 分别生成的二进制文件名字为”qemu-system-xxx”和”qemu-xxx”
# --disable-werror : 禁用编译时出现warning而报错,例如定义变量而未使用,定义函数而未使用。
# --static :使用静态编译,保证编译后的程序运行不依赖共享库,
--disable-xkbcommon --disable-libudev --disable-sdl --disable-gtk都是一些选项
最终命令:
./configure --target-list=aarch64-softmmu --enable-trace-backends=simple,log --disable-werror --static --disable-xkbcommon --disable-libudev --disable-sdl --disable-gtk
四、静态编译问题
这几个问题类似,都是缺少xxx.a静态库,导致问题。可参考3.21节qemu编译缺少*-static包 · Issue #36 · sunhaiyong1978/CLFS-for-LoongArch · GitHubhttps://github.com/sunhaiyong1978/CLFS-for-LoongArch/issues/36
解决:
yum -y install glibc-static、glib2-static、pcre-static、zlib-static
Q0:
big/little test failed
A0:
yum -y install glibc-static
Q1:
ERROR: sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T.
You probably need to set PKG_CONFIG_LIBDIR
to point to the right pkg-config files for your
build target
A1:This can happen if you install the -devel packages but not the -static packages.
yum -y install glib2-static pcre-static zlib-static
Q2:
/usr/bin/ld: cannot find -lpixman-1
/usr/bin/ld: cannot find -lzstd
A2:
yum -y install libzstd-static libpixman-1-?
另:
1.此处给几个搜索rpm的网站:
Search the RPM repository on www.rpmfind.nethttp://www.rpmfind.net/linux/rpm2html/search.php
RPM Searchhttps://rpm.pbone.net/index.php3
https://pkgs.org/search/?q=gcchttps://pkgs.org/search/?q=gcc
2.给一个 动态库缺失的问题可参考qt构建遇到 cannot find -l xxx 问题_cannot find -lstdc++_walley_li的博客-CSDN博客