Building riscv toolchain for windows

2,281 views
Skip to first unread message

Gnanasekar R

unread,
Aug 7, 2018, 1:44:07 AM8/7/18
to RISC-V SW Dev
Hi,

I am trying to build riscv toolchain for windows. In the past I have had success building it for Linux and I am comfortable with that. I wanted to build one for Windows and I am having some trouble. As such I did not find much online articles explaining 'How to build on Windows'. I followed the following link,


I think it is a bit outdated and I was able to get past intial errors by applying some patch to the Makefile. After a long time it errors out with following message,

../../../riscv-gcc/libgcc/config/riscv/atomic.c:108:1: note: in expansion of macro 'GENERATE_ALL'
 GENERATE_ALL(unsigned char, 1)
 ^~~~~~~~~~~~
configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
make[2]: *** [Makefile:10808: configure-target-libstdc++-v3] Error 1
make[1]: *** [Makefile:908: all] Error 2
make: *** [Makefile:449: stamps/build-newlib] Error 2

Is it something to do with memory at the time of linking? Someone has any idea on what am I missing?
Built with following option,

make > make1.log 2> make1.err

Attaching build log and console log in case if it helps

make1.err
make1.log

Tommy Murphy

unread,
Aug 7, 2018, 7:15:35 AM8/7/18
to RISC-V SW Dev
Another (arguably easier and more reliable) way to build the (bare metal newlib) tools is using Liviu's GNU MCU Eclipse docker based build scripts...

https://github.com/gnu-mcu-eclipse/riscv-none-gcc-build

That's the way I do it anyway and it saves a lot of hassle compared to trying to do native builds - especially on Windows/MinGW2 etc.

By default these scripts build from the GNU MCU Eclipse RISC-V tool sources repos but you can modify or possibly parameterise them to build from the riscv repos instead.

I'm sure that they could also be enhanced to build the RISC-V Linux target than bare metal toolchain if necessary.

Hope this helps
Tommy

Jim Wilson

unread,
Aug 7, 2018, 11:57:37 AM8/7/18
to Gnanasekar R, RISC-V SW Dev
On Mon, Aug 6, 2018 at 10:44 PM, Gnanasekar R <gnanase...@gmail.com> wrote:
> configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
> make[2]: *** [Makefile:10808: configure-target-libstdc++-v3] Error 1
> make[1]: *** [Makefile:908: all] Error 2
> make: *** [Makefile:449: stamps/build-newlib] Error 2

This is a common cross compiler build failure. It indicates that the
compiler you just built isn't working well enough to compile the gcc
libraries. This is sometimes a configure error. Sometimes a problem
with the build environment. There are lots of things that could be
wrong here. The interesting info will be in the file
riscv32-unknown-elf/libstdc++-v3/config.log, somewhere in the middle
you will see an attempt to check for C library features by linking a
testcase, and the link failed. You need to look at the link command
and figure out why it failed, and then figure out how to fix it.

If you are more comfortable with linux than windows, then it may be
easier to do a build canadian-cross style on a linux machine. You can
build a linux->windows cross compiler, a linux->riscv cross compiler,
and then you can use the two of those to build a windows->riscv cross
compiler on a linux machine. We call this a "canadian cross" build,
and if you do a web search for that you can probably find info on how
to do it.

Using someone else's build scripts can make this easier. I like to
use crosstools-ng myself. I don't know if it has explicit riscv
support, but I'm also not sure if it matters. It will at least show
you how to do a canadian cross if you are interested in trying.

Jim

Gnanasekar R

unread,
Aug 8, 2018, 12:31:38 AM8/8/18
to Jim Wilson, RISC-V SW Dev
Thank you Tommy and Jim. I will try these options.

f laddu

unread,
May 15, 2019, 1:51:18 AM5/15/19
to RISC-V SW Dev
Hi jim,

      --> can we Build a Canadian Tool of Linux for Windows?, if yes, then what is it's a procedure

Thanks & regards,
Ghalib khan.

Tommy Murphy

unread,
May 15, 2019, 4:25:39 AM5/15/19
to RISC-V SW Dev
Why don't you try the GNU MCU Eclipse procedure that I pointed you to earlier?

Jim Wilson

unread,
May 15, 2019, 12:29:11 PM5/15/19
to f laddu, RISC-V SW Dev
On Tue, May 14, 2019 at 10:51 PM f laddu <fkl...@gmail.com> wrote:
> --> can we Build a Canadian Tool of Linux for Windows?, if yes, then what is it's a procedure

The basic process here is to build a linux cross windows compiler,
then build a linux cross riscv-elf compiler, then use those two cross
compilers to build a canadian cross linux->windows->riscv-elf
compiler. The toolchain supports --build, --host, and --target
configure options. So for the first two you just set target, and for
the last one you set host to windows and target to riscv. If you have
a good understanding of how to build a toolchain then it shouldn't be
too hard, but you may run into some problems along the way if you
haven't done this before. Of course building a toolchain is
complicated in its own right, so this means doing 3 complicated
builds. riscv-gnu-toolchain is not set up for doing this so can't be
used directly for this. It probably works best if you configure and
build the individual toolchain parts separately. E.g. configure build
install binutils. configure build install gdb if using binutils and
gdb release sources. then drop newlib+cygwin into a gcc tree and
configure build install gcc+newlib+cygwin. Then repeat two more
times.

If you don't have a lot of experience doing this stuff, then it is
probably easier to use a tool to do it. crosstool-ng can do a
canadian cross build. This link
http://crosstool-ng.github.io/docs/toolchain-types/
talks about toolchain types, and briefly mentions how to build a
canadian cross at the end though this is a special case where you only
need two builds. For your case you need 3 builds. RISC-V is an
experimental target, so you need to enable experimental features to
use it to build a riscv compiler. The dir
samples/x86_64-w64-mingw32,arm-cortexa9_neon-linux-gnueabihf is an
example showing a config file to build a canadian cross
linux->windows->arm toolchain for instance.

Jim

Jim Wilson

unread,
May 15, 2019, 1:36:54 PM5/15/19
to f laddu, RISC-V SW Dev
On Wed, May 15, 2019 at 9:28 AM Jim Wilson <ji...@sifive.com> wrote:
> On Tue, May 14, 2019 at 10:51 PM f laddu <fkl...@gmail.com> wrote:
> > --> can we Build a Canadian Tool of Linux for Windows?, if yes, then what is it's a procedure

I see in your riscv-gnu-toolchain issue that you specifically want a
riscv-linux targetted compiler. You didn't mention that here, and I
was assuming you wanted a riscv-elf target.

Building a linux compiler from scratch is significantly more difficult
than building an embedded elf compiler from scratch. I wouldn't
recommend it. Use a tool like crosstool-ng instead.

There is a complication with a linux compiler that you really need to
use the same glibc and linux kernel version as the linux that the
target will be running. Otherwise you might end up building
riscv-linux programs that won't run on the riscv-linux target. Using
a tool like crosstool-ng complicates this a bit, as then you need to
tell crosstool-ng which glibc version and linux version is on the
target. But if you already have a target running linux, then there is
another simpler (well, for me at least) way to do this. You can
create a sysroot from the target, where the sysroot contains
everything the compiler needs, e.g. /usr/include, /lib, /usr/lib, and
any target specific directories such as /lib64 for a 64-bit target.
You can then use --with-sysroot= when configuring binutils and gcc to
tell it to use the sysroot you copied from the target. You don't need
to build glibc in this case, since you already gave a copy of it to
gcc. So you can now do this like an embedded elf bulid, where you can
configure build install a windows binutils/gdb/gcc, configure build
install a riscv-linux binutils/gdb/gcc, and then configure build
install the windows-cross-riscv-linux binutils/gdb/gcc. The windows
build still needs to be done with newlib and cygwin dropped into the
gcc source dir, but the two riscv-linux builds use --with-sysroot= for
the library.

Jim

f laddu

unread,
May 21, 2019, 8:37:17 AM5/21/19
to RISC-V SW Dev, fkl...@gmail.com
I Got the Windows Tools.....

I have gone through the following steps.

steps:-

1> cloned the crossTool-NG &Tool, with that Build the x86_64-w64-mingw32,
ct-ng x86_64-w64-mingw32
ct-ng build

Got x86_64-w64-mingw32 Tools. 

2> Export those Tool PATH i.e:export PATH=<x-tool/x86_64-w64-mingw32/bin>:$PATH

3> cloned riscv-gnu-tools.

4>  ./configure --with-host=x86_64-w64-mingw32 --target=riscv64-unknown-linux-gnu --prefix=<PATH> --without-system-zlib

5> make linux

6> Here binutils is successfully Build, But while Building Gcc Faced an Below Error

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

7> For that, i have Run cd riscv-gnu-toolchain/riscv-gcc && ./contrib/download_prerequisites

with that resolved the issue.

8> Got the Executables.

9> copied those Floder to windows machine.

10> open the cmd terminal & try to compile a Basic Hello world code. But facing a Error as ...... 

libwinpthread-1.dll was not found..  
Downloaded that file and copied to C:/windows/system32/
Got resoled that issue.
11> Again try to compile it, Got another the issue ...........The Application was Unable to Start Correctly (0xc000007b)


can u plz help me to resolve this issue...

Thanks & Regards.
khan.

lkcl

unread,
May 21, 2019, 11:36:49 AM5/21/19
to RISC-V SW Dev


On Tuesday, August 7, 2018 at 6:44:07 AM UTC+1, Gnanasekar R wrote:
Hi,

I am trying to build riscv toolchain for windows. In the past I have had success building it for Linux and I am comfortable with that. I wanted to build one for Windows and I am having some trouble.

gnanasekar, laddu, hi,

"having some trouble" - this should give you a clue.

around 2008-2009 i decided just for laughs to compile python using msys and mingw32 (with a view to compiling python-webkit for windows).  to make it even more fun i did so *under Wine*.

so let's restate that, one.  i decided to compile a windows application that required over 40 complex dependencies... under a software emulator (wine) so running linux but actually emulating windows, running applications *designed* for linux (msys) but actually compiled up for windows and then running them under an emulator, in order to compile python for mingw32 (an unsupported platform), in order to...

... are you getting the picture?  watching the autoconf script (./configure) run at a rate of one line *per second* due to a bug in msys that was pulling in the entirety of x11 libfonts just because of (as it turned out) an Alt-Sys-Req #define, was hilarious for about a good oooo 5 minutes.

the point of telling you this tale is: if you are considering cross-compiling riscv toolchains for windows, DON'T.

STOP what you are doing, and consider alternatives, before you waste too much precious time on this.  risc-v is *too new* to be messing about trying to be the first person - ever - to cross-compile gcc and associated tools on windows.

install the POSIX subsystem on windows (now known under some other name) and install whatever GNU/Linux Distro that is easiest, install qemu or some other Virtual Machine Emulator, dual-boot the hardware, rent a VM somewhere, buy another computer do anything and i mean ANYTHING to avoid going down this road.

you're basically looking at a *triple* layer here, just as i was when doing the python / webkit cross-compiling under Wine: windows -> mingw32-cross-compiler -> riscv-native.

it's just not a good idea, as there are too many hoops to jump through, and so many parts are untested you're asking for trouble.

that having been said: if of course you are a compiler expert, with decades of embedded systems cross-compiling experience, it should not take long to solve the issues and carry out any necessary fixes to the compiler toolchains along the way.

have i got the message across yet?  don't do it!  really!

l.


Tommy Murphy

unread,
May 21, 2019, 12:16:54 PM5/21/19
to lkcl, RISC-V SW Dev
Last time (a few months ago) I tried ct-NG I had no problems cross building the bare metal and Linux RISC-V toolchains on Linux for Windows so I'm surprised at the comments above.
If I get a chance I'll try again and post back with results.



Jim Wilson

unread,
May 21, 2019, 12:20:38 PM5/21/19
to f laddu, RISC-V SW Dev
On Tue, May 21, 2019 at 5:37 AM f laddu <fkl...@gmail.com> wrote:
> 1> cloned the crossTool-NG &Tool, with that Build the x86_64-w64-mingw32,
> ct-ng x86_64-w64-mingw32
> ct-ng build

This part is OK.

> 3> cloned riscv-gnu-tools.

This part isn't. Don't use riscv-gnu-tools. Use crosstool-ng which
you already have. You need to use crosstool-ng 3 times. First build
a cross compiler to windows which you already did. Then build a cross
compiler to riscv-linux. Then build a canadian cross for
linux->windows->riscv-linux.

riscv-gnu-tools is convenient for building riscv cross compilers on a
linux system. It shouldn't be used for anything else. It isn't
designed to be useful for anything else.

Jim

f laddu

unread,
May 21, 2019, 11:59:08 PM5/21/19
to RISC-V SW Dev, fkl...@gmail.com
As you said i Build Both the Tool's.

ct-ng x86_64-w64-mingw32
ct-ng build

        ct-ng riscv64-unknown-linux-gnu
ct-ng build

Got Both Tool's & export the PATH.

Next Run the Canadian options..

ct-ng x86_64-w64-mingw32,riscv64-unknown-linux-gnu

Here it's failing, as Shown Below....

make: *** No rule to make target 'x86_64-w64-mingw32,riscv64-unknown-linux-gnu'.  Stop.

Help me to sort out this issue...

Thanks...

Jim Wilson

unread,
May 22, 2019, 2:03:17 AM5/22/19
to f laddu, RISC-V SW Dev
On Tue, May 21, 2019 at 8:59 PM f laddu <fkl...@gmail.com> wrote:
> Next Run the Canadian options..
> ct-ng x86_64-w64-mingw32,riscv64-unknown-linux-gnu
>
> Here it's failing, as Shown Below....
> make: *** No rule to make target 'x86_64-w64-mingw32,riscv64-unknown-linux-gnu'. Stop.

There is no pre-defined config file for that. You can manually
configure the canadian cross using ct-ng menuconfig, or you can create
a config file by copying one of the other canadian cross config files
and modifying it to work for a riscv canadian cross.

Try "ls samples" in a crosstool-ng source tree to see the pre-defined
config files. Or run "ct-ng list-samples" to see the list.

Jim
Reply all
Reply to author
Forward
0 new messages