An error when running spike

I’m a rookie of RISC-V. When I finished the installation of riscv-tools and I wanted to test it, but an error occurred. My os is ubuntu 16.04 and commands are shown below:

$ git clone https://github.com/riscv/riscv-tools.git
$ cd riscv-tools
$ git submodule update --init --recursive
$ export RISCV=~/RISCV/riscv-tools-install
$ export PATH=$PATH:$RISCV/bin
$ ./build.sh
$ cd …
$ echo -e ‘#include <stdio.h>\n int main(void) { printf(“Hello world!\n”); return 0; }’ > hello.c
$ riscv64-unknown-elf-gcc -o hello hello.c
$ spike pk hello

However, the final command can’t work correctly. The error message is:
terminate called after throwing an instance of 'std::runtime_error’
what(): could not open pk (did you misspell it? If VCS, did you forget +permissive/+permissive-off?)

How can I solve this problem?

The error message seems pretty clear, it is telling you that spike can’t find the pk program. The readme says spike will find it automatically, but this is apparently wrong or out-of-date. You can specify the path to the pk file, or put a copy in your current dir. Or maybe put $RISCV/riscv64-unknown-elf/bin on your path.

OK. It works.

bro how to add it to my path i cant understand
i am beginner
pls tell me

FIrst you need the name of the directory where you installed your riscv cross compilers. Let’s call this installdir. To set your path, you want to do something like
export PATH=$PATH:installdir/bin
where you replace installdir with the actual directory name where the programs are installed. This assumes that your shell is bash or a compatible POSIX shell. If you are using csh then the command will be different. Or if you are on a Windows machine, and not using a shell like cygwin, then you need a different command.

You can always specify absolute pathnames, e.g instead of running riscv64-unknown-elf-gcc you can run /installdir/bin/riscv64-unknown-elf-gcc where again you must replace installdir with the name of the directory where the program is installed.

Try giving the full pathname for the pk program to spike. I don’t think that spike uses PATH to find pk. Or alternatively, create a symbolic link in the current directory pointing at the pk program so that spike can find it.

I tried:
spike $(which pk) hello
and:
spike /home/sifive-riscv/riscv-build/riscv/riscv32-unknown-elf/bin/pk hello

It did not give an error anymore, but it did not show anything. It was hanging and did not nothing.

If there is no error from spike then pk should be running OK, and it may be a problem with your hello world program. You can try generating instruction traces from spike and looking at them. If spike is hanging, then the instruction trace will stop. If pk or hello are hanging, then the instruction trace should continue and show an infinite loop of some sort.