3

I can't get ANYTHING working on linux. I'm trying to compile CudaMiner. Output of sudo make:

ypt-jane.o `test -f 'scrypt-jane.cpp' || echo './'`scrypt-jane.cpp
mv -f .deps/cudaminer-scrypt-jane.Tpo .deps/cudaminer-scrypt-jane.Po
nvcc -g -O2 -Xptxas "-abi=no -v" -arch=compute_10 --maxrregcount=64 --ptxas-options=-v -I./compat/jansson -o salsa_kernel.o -c salsa_kernel.cu
/bin/bash: nvcc: command not found
make[2]: *** [salsa_kernel.o] Error 127
make[2]: Leaving directory `/var/progs/CudaMiner'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/progs/CudaMiner'
make: *** [all] Error 2

So, kind of interesting. Output of nvcc:

nvcc fatal   : No input files specified; use option --help for more information

Whereas the output of sudo nvcc:

sudo: nvcc: command not found

I have identical exports listed in ~/.bashrc AND /etc/bash.bashrc. (Nvcc is located in: /usr/local/cuda-5.0/bin/nvcc)

I also tried changing the current path, to no avail:

$ sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ PATH=$PATH:/usr/local/cuda-5.0/bin/nvcc
$ sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Thanks in advance!

3 Answers 3

5

So apparently, nvcc is not on the PATH when you run it with sudo. You can confirm this with:

sudo bash -c 'echo $PATH'

The easiest solution is to call sudo with the absolute path of nvcc:

sudo $(which nvcc)

When running commands without absolute path like nvcc, sudo uses the value of the secure_path configuration in /etc/sudoers as the PATH, for example in my system:

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

So even if you set PATH in one of the startup files that the shell normally sources, it won't work. If you want to make sudo nvcc work temporarily, just to get your build working, I think you have two options:

  • Edit the installer script and change the lines with sudo nvcc to sudo /path/to/nvcc
  • Create a symlink to nvcc in one of the directories listed in secure_path, like this: sudo ln -s /path/to/nvcc /sbin/nvcc

UPDATE

If you have a hard time finding the path of nvcc, you can try these commands, in this order (they get slower and slower), until you find a match:

which nvcc
find /usr/local/cuda-5.0 -name nvcc
find /usr/local/ -name nvcc
find /opt -name nvcc
find / -name nvcc
7
  • Is there a way I can include /usr/local/cuda-5.0/bin/ just for the current session in the terminal such that when time comes and make script calls upon it it will find it? I don't think I'll ever need it again.
    – dsp_099
    Mar 2, 2014 at 6:15
  • @dsp_099 yup, see my updated answer
    – janos
    Mar 2, 2014 at 6:36
  • I tried the symlink way with the command listed and that didn't work, however editing the installer script worked great. Might also want to include the link to askubuntu.com/questions/231503/nvcc-compiler-setup-ubuntu-12-04 so people who are noobs(like myself) can let this be a one stop shop May 28, 2014 at 17:56
  • Thanks @JamesTobin! I'm happy to add links that improve the answer, but I don't see the added value in the link you posted. Can you explain?
    – janos
    May 28, 2014 at 21:23
  • For those people who wouldn't know how to find where their nvcc is located. Its hard to add it to the path if you don't know where it is May 28, 2014 at 21:25
0

You can use -E option of sudo to preserve your user environment. From the man page:

 -E, --preserve-env
             Indicates to the security policy that the user wishesto preserve their existing environment
             variables.  The security policy may return an error if the user does not have permission to
             preserve the environment.

You can test this with:

$ sudo bash -c 'echo $PATH'

and then

sudo nvcc
-1

The cause might be a read-only folder. In my case the 'Make' file that calls nvcc was in a read-only folder. Changing the folder permission settings solved my problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .