3

I have make installed, I have the riscv32-unknown-linux-gnu toolchain installed.

I have added riscv/bin to my path. I can successfully execute any of the toolchain commands in the shell. e.g. riscv32-unknown-linux gnu-as ... hello.s -o boot.o works.

When i run which riscv32-unknown-linux-gnu-as, there is nothing printed to the terminal.

When I run make in the directory of my makefile i get

riscv32-unknown-linux-gnu-as -march=rv32i -mabi=ilp32 hello.s -o hello.o
make: riscv32-unknown-linux-gnu-as: Command not found
Makefile:18: recipe for target 'hello.o' failed
make: *** [hello.o] Error 127

It seems this is a problem with my path? I'm not sure why which and make can't find it, but I can execute it just fine.

** EDIT **

~/.profile

export PATH="~/riscv/bin:$PATH"

The only thing I can think of is something with the path is weird, this is on WSL

1 Answers1

3

The tilde character (~) does not usually expand to your home directory when it is used within double quotes. If you look at your $PATH value, you will see that it contains a literal tilde, not the full path to you home directory (which it would have done if you hadn't double quoted the value in the assignment).

The shell that make uses to execute shell commands (/bin/sh, which may be the dash shell), and your which command, does not do an extra tilde expansion step on the values in $PATH. This is why both make and which fail to find that command that you need to use.

The bash shell, on the other hand, does an extra tilde expansion step when examining the $PATH, so this is why you can use that command on the command line.

In this scenario, it is bash which is the odd one out, as utilities are not required to expand the tilde when they are using the $PATH variable.

Solutions:

  1. Use $HOME rather than ~ in your .profile. $HOME always behaves like a normal variable.

  2. Don't quote the value in the assignment (it's not needed anyway).

  3. Make make use bash for running the shell commands in the Makefile by setting the make variable SHELL to the path of the bash executable on your system (I would not do this as I would argue that it's the value of you $PATH that is wrong, not the /bin/sh shell's handling of it).

Further reading:

Also note that since PATH is already exported (it's an environment variable), you never have to export it in your shell's startup files.

Kusalananda
  • 333,661