QEMU README
QEMU is a generic and open source machine & userspace emulator and virtualizer.
QEMU官网链接:https://www.qemu.org/ ,GitHub地址:https://github.com/qemu/qemu
Install QEMU
To download and build QEMU 6.1.0:
wget https://download.qemu.org/qemu-6.1.0.tar.xz
tar xvJf qemu-6.1.0.tar.xz
cd qemu-6.1.0
在进行configure
之前需要注意:1. 安装python3.6及以上版本。2. 安装GCC v7.5 or Clang v6.0及以上
./configure --prefix=/home/zgl/qemu # --prefix指定安装路径
ERROR1:ERROR: Cannot use 'xxxx/python/bin', Python >= 3.6 is required. Use --python=/path/to/python to specify a supported Python.
解决办法:指定Python3.6,--python=/home/zgl/python3.6/bin/python3.6
ERROR2:ERROR: You need at least GCC v7.5 or Clang v6.0 (or XCode Clang v10.0)
解决办法:指定GCC或LLVM,--cc=/home/zgl/gcc8.2.0/bin/gcc --cxx=/home/zgl/gcc8.2.0/bin/g++
ERROR3: glib-2.56 gthread-2.0 is required to compile QEMU
解决办法:下载glib2.56编译安装
编译时错误1:configure: error: Python interpreter is too old
解决办法:PYTHON="/home/zgl/python3.6/bin/python3.6"
编译时错误2:configure: error: *** Could not find libmount
解决办法:--enable-libmount=no
完整编译如下:
sudo PYTHON="/home/zgl/python3.6/bin/python3.6" ./autogen.sh --enable-libmount=no
make -j 32
sudo make install
glib问题解决回到qemu继续configure
ERROR4:ERROR: Could not detect Ninja v1.7 or newer
sudo apt install re2c
git clone git://github.com/ninja-build/ninja.git && cd ninja
./configure.py --bootstrap
sudo cp ninja /usr/bin/
此时再次清除build并进行编译:
./configure --prefix=/home/zgl/qemu --python=/home/zgl/python3.6/bin/python3.6 --cc=/home/zgl/gcc8.2.0/bin/gcc --cxx=/home/zgl/gcc8.2.0/bin/g++
make -j 4
make install
另一种安装方式: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
Intall mips compiler
sudo apt-get install emdebian-archive-keyring
sudo apt install linux-libc-dev-mips-cross libc6-mips-cross libc-dev-mips-cross binutils-mips-linux-gnu
sudo apt install gcc-mipsel-linux-gnu g++-mipsel-linux-gnu
Test
hello.c
#include <stdio.h>
int main(){
printf("Hello world\n");
return 0;
}
编译:mipsel-linux-gnu-gcc -O3 hello.c -o hello --static
注意使用--static
不然运行时可能出现qemu-mipsel: Could not open '/lib/ld.so.1': No such file or directory
错误
运行:~/qemu/bin/qemu-mipsel ./hello
输出:Hello world