• 参考文档

安装 RISC-V 交叉编译工具链 - USTC CECS 2023

  • 安装依赖库
sudo apt update

sudo apt -y install autoconf automake autotools-dev curl python3 python3-pip
sudo apt -y install libmpc-dev libmpfr-dev libgmp-dev gawk
sudo apt -y install build-essential bison flex texinfo gperf libtool patchutils
sudo apt -y install bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev

  • 下载代码及编译

我用的是Ubuntu22虚拟机,耗时很久。

git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
mkdir build
cd build

../configure --prefix=/opt/riscv64 --enable-multilib --target=riscv64-linux-multilib
sudo make linux -j 4
  • 测试
$ echo 'export PATH=/opt/riscv64/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc

$ riscv64-unknown-linux-gnu-gcc --version
riscv64-unknown-linux-gnu-gcc (gc891d8dc23e) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐