一定要记得加–recursive, 这是用于循环克隆git子项目,要不然克隆下来的qemu等文件夹是空的
git clone --recursive https://gitee.com/mirrors/riscv-gnu-toolchain.git
也可以按下面的方法(更快一点,可以看到每个模块下载进度),将上面git命令中的–recursive去掉,再单独下载每个模块
git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
这样下载后qemu等文件夹下是空的,需要执行以下命令后,将riscv-qemu下内容copy到qemu,将riscv-binutils-gdb下内容copy到riscv-gdb和riscv-binutils
git clone https://mirrors.tuna.tsinghua.edu.cn/git/qemu.git
git clone https://github.com/riscv/riscv-newlib.git
git clone https://github.com/riscv/riscv-binutils-gdb.git
git clone https://github.com/riscv/riscv-dejagnu.git
git clone https://github.com/riscv/riscv-glibc.git
git clone https://github.com/riscv/riscv-gcc.git
其实我使用的方法是直接把qemu等空文件夹删掉,再用mv指令将riscv-qemu等文件夹直接重命名,如
rm -rf qemu
mv riscv-qemu qemu
(mv命令用于重命名时,目录下不能有要命名的同名文件夹,要不就是个移动命令了)
vi ~/.bashrc
在文件中添加语句
export RISCV="/home/XXX/riscv-gnu-toolchain"
export PATH=$PATH:$RISCV/bin
保存退出后执行
source ~/.bashrc
sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev gawk
./configure --prefix=$RISCV --with-arch=rv32imc --with-abi=ilp32
make
编写hello.c文件
就可以用编译器riscv32-unknown-elf-gcc进行编译了