How to Install the RISC-V GNU Toolchain

 

# UPDATED 10/24/2019

 

# see https://github.com/riscv/riscv-gnu-toolchain for more details.

 

# Several standard packages are needed to build the toolchain. On Ubuntu, executing the following command should suffice:

sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

sudo apt-get update

 

# On Fedora/CentOS/RHEL OS, executing the following command should suffice:

sudo yum install autoconf automake libmpc-devel mpfr-devel gmp-devel gawk bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel

# I also had to add to my CentOS7

yum install python3

# Also the gnu-toolchain requires MAKE ver 4 or higher

scl enable devtoolset-7 bash

sudo yum install centos-release-scl

sudo yum install devtoolset-7-make

sudo yum update

 

 

# Pick an install path. If you choose, say, /opt/riscv, then add /opt/riscv/bin to your PATH now. Also add the above two lines to your .bashrc file for future use when you login

export RISCV=/opt/riscv
export PATH=$PATH:$RISCV/bin

 

# reboot your computer

 

# create a temp folder

mkdir riscv

cd riscv

git clone https://github.com/riscv/riscv-gnu-toolchain

cd riscv-gnu-toolchain

git submodule update --init --recursive

 

# To build a cross-compiler with support for both RISCV 32-bit and 64-bit, run the following commands:

# riscv-tests will need this build

su root

./configure --prefix=/opt/riscv --enable-multilib

make

exit

ls

# remove temp folder

cd ..

rm -rf riscv


--------------------------------------

An easier way to get an embedded elf toolchain is to download a prebuilt one that someone else built, e.g. like the ones on the SiFive web site.
see bottom of webpage at https://www.sifive.com/boards