What is the best way? Here are my solutions:
echo $PATH | sed "s/:/\n/g" | grep "cuda/bin" | sed "s/\/bin//g" | head -n 1 which nvcc | sed "s/\/bin\/nvcc// which nvcc | head -c -10
All of them are based on PATH. Instead, libraries could be found; this would be more reliable if PATH did not have CUDA paths.
I use this in a makefile.
source share