"error while loading shared libraries: libcublas.so.8.0" when launching with sudo

When i launch my code with sudo rights, i get this error:

error while loading shared libraries: libcublas.so.8.0

But no such error when launching without sudo. Also runs with sudo on other devices.
My ~/.bashrc has these lines:

export PATH=$PATH:/usr/local/cuda-8.0/bin:/usr/local/cuda-8.0/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

When i do

ls $LD_LIBRARY_PATH

, i get:

ls: cannot access ':/usr/local/cuda-8.0/lib64': No such file or directory

even though the directory is there.
sudo ldconfig doesn’t solve it either.
Someone suggested doing this:

sudo echo "/usr/local/cuda-7.0/lib64" > /etc/ld.so.conf.d/cuda.conf
sudo ldconfig

, but i dont even have “/etc/ld.so.conf.d/cuda.conf”.
Any ideas?

sudo (i.e. root user) and ordinary user will have a different set of environment variables

The variables set up in your .bashrc file will apply to the ordinary user, but will not be automatically set up for the root user, or when you use sudo

If you want the same environment variables in effect when you are running sudo commands, you will have to make that happen by manually setting them up, or sourcing them, or using some other method.

Also note that the linux install guide:

http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions

actually recommends the following format:

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

which is different than what you have. I believe you are having trouble because your initial LD_LIBRARY_PATH is empty. If you use the approach recommended in the linux install guide, I believe it will fix your second issue.

That returns

bash: export: `:/usr/local/cuda-8.0/lib64': not a valid identifier

And i still stand by my statement that the directory is in fact there.

OK try this:

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64

and I never said the directory wasn’t there. The problem is your export statement, combined with the previous value of the environment variable, may create a directory that “isn’t there” because of the : in the directory path.

The LD_LIBRARY_PATH environment variable represents a set of search paths for use by a system (the dynamic “run-time” linker) that knows how to traverse that set. It is not necessarily formatted in a way that is directly usable by the ls command. So your “test” of using “ls $LD_LIBRARY_PATH” is not a valid test, in the general case.

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64

returns no error, but when launching with sudo, program now throws this error:

error while loading shared libraries: libcublas.so.8.0: cannot open shared object file: No such file or directory

. After exporting LD_LIBRARY_PATH and $PATH, as in install guide,

ls $LD_LIBRARY_PATH

now returns a full list of libs. So something’s already better.

Manually moving all the required libs to /usr/local/libs/ and linking them solved the issue, but this is not the right solution.

Just so you know this error might be caused by another export value you have set that isn’t accurate.