riscv-collab / riscv-gnu-toolchain

GNU toolchain for RISC-V, including GCC
Other
3.53k stars 1.16k forks source link

Build toolchain on Linux for Windows using mingw-w64 #892

Closed ILoveSpeccy closed 3 years ago

ILoveSpeccy commented 3 years ago

I'm trying to build toolchain on ubuntu 20.04 for Windows using mingw-w64:

./configure --prefix=/opt/riscvgcc --enable-multilib --with-host=i686-w64-mingw32 --without-system-zlib
make -j

and get the following error before libraries are built: /bin/bash: riscv64-unknown-elf-gcc: command not found

/opt/riscvgcc/bin is included in PATH.

Should I pay attention to something?

cmuellner commented 3 years ago

I recommend not use make -j (without an argument) as this does the following:

       -j [jobs], --jobs[=jobs]
            Specifies the number of jobs (commands) to run simultaneously.  If
            there  is  more than one -j option, the last one is effective.  If
            the -j option is given without an argument, make  will  not  limit
            the number of jobs that can run simultaneously.

Additionally, I don't think that your use-case (build a Windows cross-toolchain on a Linux system) is supported in any way. I recommend building a Windows cross-toolchain on a Windows system. There you probably first want to install Mingw or Cygwin. I can't give more help as I don't have access to a Windows machine.

ILoveSpeccy commented 3 years ago

Thanks! I built a Linux version of the toolchain and added its bin folder into PATH. Now it works! But I don't know if it's the right way.

p.S. I have already tried to build the toolchain in Windows using msys2. It didn't work either (forgot the error message). Compilation under Windows feels ten times slower (antivirus is disabled).

jim-wilson commented 3 years ago

It is easier to do the build on a linux machine than on a Windows machine, but riscv-gnu-toolchain doesn't have direct support for this. The SiFive toolchain sources do though. You could try looking at sifive/freedom-tools. This is larger and more complicated to build than riscv-gnu-toolchain though. There is also crosstool-ng. This has support for canadian cross builds, but you might need to write a config file for the canadian cross riscv64-elf build. http://crosstool-ng.github.io/ Read the docs if interested in this.

ILoveSpeccy commented 3 years ago

Many thanks for the support!

ILoveSpeccy commented 3 years ago

I was able to build it using the msys2 under Windows! There were errors in gdb compilation and I turned it off (--disable-gdb). I built a working toolchain for picorv32 with the following commands:

../configure --prefix=/build/riscvgcc --with-multilib-generator="rv32e-ilp32e--c;rv32em-ilp32e--c;rv32i-ilp32--c;rv32im-ilp32--c" --disable-gdb
make -j$(nproc)

Thank you again!