Search code examples
linuxbashcudanvcc

nvcc runs from command line but not from shell


I tried to run this command form command line:

nvcc src/lib/Globals.cpp src/lib/Comp/* src/lib/Decomp/* src/main.cpp -lpthread  -o debug/TEST

it runs perfectly,generates errors or warnings when compiling and so on.but when executed from a shell it produces this error:

./debug/test.sh: line 137: nvcc: command not found

this is the relevant part of my .bashrc file although I don't see how that might be the problem.

export CUDA_HOME=/SomePATH/CUDA
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=$CUDA_HOME/lib:$CUDA_HOME/lib64:$LD_LIBRARY_PATH

the same error happens with nvprof.


Solution

  • .bashrc is only read for interactive shells. Move your commands to set up the environment for CUDA to .profile instead, which is also read for noninteractive shells (batch jobs/shell scripts).

    You can read up about shell initialization files by running info bash and going to Bash Features, then Bash Startup Files