# An error when running spike

**URL:** <https://forums.sifive.com/t/an-error-when-running-spike/1247>\
**Category:** RISC-V\
**Created:** [May 24, 2018, 6:10am UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247 "2018-05-24T06:10:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![flame](https://avatars.discourse-cdn.com/v4/letter/f/ebca7d/32.png) [@flame](https://forums.sifive.com/u/flame)\
**Post date:** [May 24, 2018, 6:10am UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/1 "2018-05-24T06:10:59Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [May 24, 2018, 9:34pm UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/2 "2018-05-24T21:34:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![flame](https://avatars.discourse-cdn.com/v4/letter/f/ebca7d/32.png) [@flame](https://forums.sifive.com/u/flame)\
**Post date:** [June 2, 2018, 6:47am UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/3 "2018-06-02T06:47:37Z")

</div>

OK. It works.

---

<div class="post-metadata">

**Author:** ![ssaran](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@ssaran](https://forums.sifive.com/u/ssaran)\
**Post date:** [July 8, 2019, 5:45am UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/4 "2019-07-08T05:45:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [July 8, 2019, 9:50am UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/5 "2019-07-08T09:50:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [June 16, 2020, 4:31pm UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/7 "2020-06-16T16:31:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kingstone](https://avatars.discourse-cdn.com/v4/letter/k/5daacb/32.png) [@kingstone](https://forums.sifive.com/u/kingstone)\
**Post date:** [June 16, 2020, 6:19pm UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/8 "2020-06-16T18:19:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [June 18, 2020, 6:12pm UTC](https://forums.sifive.com/t/an-error-when-running-spike/1247/9 "2020-06-18T18:12:40Z")

</div>

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.
