Skip to content

Instantly share code, notes, and snippets.

@jdryg
Last active April 2, 2024 09:25
Show Gist options
  • Save jdryg/a61ca450aa86c200fb187c0a1d29d4b6 to your computer and use it in GitHub Desktop.
Save jdryg/a61ca450aa86c200fb187c0a1d29d4b6 to your computer and use it in GitHub Desktop.
Cross-compile RISC-V toolchain on Ubuntu with MinGW
  1. Install MinGW packages on Ubuntu
sudo apt install mingw-w64
  1. Download, build and install GMP for MinGW

    1. Download the src package from https://sourceforge.net/projects/mingw/files/MinGW/Base/gmp/gmp-6.1.2/
    2. Extract somewhere on your Ubuntu machine and enter the directory.
    3. Run ./configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-mingw32
    4. make
    5. sudo make install
  2. Download, build and install mpfr for MinGW

    1. Download the src package from https://sourceforge.net/projects/mingw/files/MinGW/Base/mpfr/mpfr-3.1.5/
    2. Extract somewhere on your Ubuntu machine and enter the directory.
    3. Run ./configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared
    4. make
    5. sudo make install
  3. Download, build and install mpc for MinGW

    1. Download the src package from https://sourceforge.net/projects/mingw/files/MinGW/Base/mpc/mpc-1.0.1/
    2. Extract somewhere on your Ubuntu machine and enter the directory
    3. Run ./configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared
    4. make
    5. sudo make install
  4. Build riscv-gnu-toolchain

    1. Clone the repository from https://github.com/riscv/riscv-gnu-toolchain
    2. Enter the directory and configure the build with ./configure --prefix=<absolute path of toolchain install dir> --with-arch=<you arch of choice> --with-abi=<your ABI of choice> --with-host=x86_64-w64-mingw32 --without-system-zlib
    3. make
    4. Wait and hope everything builds fine... :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment