Riscv-gun-toolchain的编译以及安装
操作系统:Ubuntu20.04 Shell:zsh
参考文章:
- https://blog.csdn.net/qq_42866646/article/details/108289683
- https://www.codeleading.com/article/67025921158/#:~:text=%E5%A6%82%E6%9E%9C%E6%8A%A5%20ERROR%3A%20glib-2.48%20gthread-2.0%20is%20required%20to%20compile,not%20present.%20Please%20install%20the%20pixman%20devel%20package
从github上下载项目
git clone https://github.com/riscv/riscv-gnu-toolchain
如果下载速度太慢,可以从gitee下载。
git clone https://gitee.com/mirrors/riscv-gnu-toolchain.git
不建议使用git clone --recursive https://github.com/riscv/riscv-gnu-toolchain ,有些子项目的下载速度会很慢。
cd riscv-gun-toolchain 进入到项目文件夹(下面的所有操作都在此路径下执行),查看.gitmodules 文件,里面列举了子模块的下载地址,分支,以及目标文件夹。
[submodule "riscv-binutils"]
path = riscv-binutils
url = https://github.com/riscv-collab/riscv-binutils-gdb.git
branch = riscv-binutils-2.36.1
[submodule "riscv-gcc"]
path = riscv-gcc
url = https://github.com/riscv-collab/riscv-gcc.git
branch = riscv-gcc-10.2.0
[submodule "riscv-glibc"]
path = riscv-glibc
url = git://sourceware.org/git/glibc.git
[submodule "riscv-dejagnu"]
path = riscv-dejagnu
url = https://github.com/riscv-collab/riscv-dejagnu.git
branch = riscv-dejagnu-1.6
[submodule "riscv-newlib"]
path = riscv-newlib
url = git://sourceware.org/git/newlib-cygwin.git
branch = master
[submodule "riscv-gdb"]
path = riscv-gdb
url = https://github.com/riscv-collab/riscv-binutils-gdb.git
branch = fsf-gdb-10.1-with-sim
[submodule "qemu"]
path = qemu
url = https://git.qemu.org/git/qemu.git
可以将.gitmodules 文件内容改成
[submodule "riscv-binutils"]
path = riscv-binutils
url = https://gitee.com/mirrors/riscv-binutils-gdb.git
branch = riscv-binutils-2.36.1
[submodule "riscv-gcc"]
path = riscv-gcc
url = https://gitee.com/mirrors/riscv-gcc.git
branch = riscv-gcc-10.2.0
[submodule "riscv-glibc"]
path = riscv-glibc
url = git://sourceware.org/git/glibc.git
[submodule "riscv-dejagnu"]
path = riscv-dejagnu
url = https://gitee.com/mirrors/riscv-dejagnu.git
branch = riscv-dejagnu-1.6
[submodule "riscv-newlib"]
path = riscv-newlib
url = git://sourceware.org/git/newlib-cygwin.git
branch = master
[submodule "riscv-gdb"]
path = riscv-gdb
url = https://gitee.com/mirrors/riscv-binutils-gdb.git
branch = fsf-gdb-10.1-with-sim
[submodule "qemu"]
path = qemu
url = https://mirrors.tuna.tsinghua.edu.cn/git/qemu.git
然后在riscv-gun-toolchain 的路径下执行git submodule update --init --recursive ,会自动完成所有子模块的下载。中途可能有些比较大模块下载失败,因此我推荐多开几个终端,使用下面的命令分开下载。
git clone -b riscv-binutils-2.36.1 https://gitee.com/mirrors/riscv-binutils-gdb.git ./riscv-binutils
git clone -b riscv-gcc-10.2.0 https://gitee.com/mirrors/riscv-gcc.git ./riscv-gcc
git clone git://sourceware.org/git/glibc.git ./riscv-glibc
git clone -b riscv-dejagnu-1.6 https://gitee.com/mirrors/riscv-dejagnu.git ./riscv-dejagnu
git clone git://sourceware.org/git/newlib-cygwin.git ./riscv-newlib
git clone -b fsf-gdb-10.1-with-sim https://gitee.com/mirrors/riscv-binutils-gdb.git ./riscv-gdb
git clone https://mirrors.tuna.tsinghua.edu.cn/git/qemu.git ./qemu
如果有些比较大的模块下载失败,我的解决方法是增大git的下载缓存。
sudo git config --global http.postBuffer 524288000
查看git的配置
git config --list
下载编译项目用到的工具
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 -y
bash环境在用户目录下的.bashrc 文件中添加下面的环境变量,zsh环境在用户目录下的.zshrc 文件中添加下面的环境变量。
export RISCV="/opt/riscv-gun-toolchain"
export PATH=$PATH:$RISCV/bin
我选择的安装位置是/opt/riscv-gun-toolchain ,这个可以自定义。 在终端执行
./configure --prefix=$RISCV
因为使用的是Ubuntu,64位系统,根据文档的提示执行上面的语句。其他的系统请查看文档。
然后开始编译项目,这个过程会很久,久到足够跑完10公里。
sudo make
上述步骤完成之后,使用下面的命令验证是否安装成功。如果显示版本信息则说明安装成功。
riscv64-unknown-elf-gcc --version
如果遇到其他问题,欢迎在底下评论。
|