27

I'm trying to get my Cuda SDK samples running, but I get the following error:

./bandwidthTest: error while loading shared libraries:
                 libcudart.so.4: cannot open shared object file:
                 No such file or directory

Why can I compile the example successfully, but not run it? Is there a way to specify the path to the CUDA runtime library manually?

10
  • How did you compile the code?
    – Adam27X
    May 30, 2012 at 1:40
  • Did you remember to update your LD_LIBRARY_PATH and PATH environmental variables in your .bashrc file, or whatever configuration file associated with your shell?
    – sj755
    May 30, 2012 at 1:43
  • Sounds like the lib was probably renamed, is there anything with "libcudard" in its name in the /usr/lib folder?
    – user406009
    May 30, 2012 at 1:43
  • where is the .bashrc file? i compiled the code by the makefile in NVIDIA_GPU_Computing_SDK/C... and yes libcudart.so.4 is in /usr/lib/...
    – Alex
    May 30, 2012 at 2:00
  • Your .bashrc file is located in your home directory. It's hidden, so you have to display hidden files before you can open it in gedit. BTW, to reply to a comment put an @username before the comment so that the commenter can be notified.
    – sj755
    May 30, 2012 at 2:21

8 Answers 8

80

try:

32-bit: sudo ldconfig /usr/local/cuda/lib

64-bit: sudo ldconfig /usr/local/cuda/lib64

cheers

5
  • wow thanks. I was using Theano and getting: "Failed to compile cuda_ndarry.cu: libcublas.so.6.0: cannot open shared object file: No such file or directory" this fixed it :D Jul 19, 2014 at 22:42
  • 1
    Is is related to export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64? Oct 13, 2014 at 17:52
  • When running this I get an error but it solves the problem nonetheless! Thanks!
    – Gu1234
    Feb 28, 2016 at 8:35
  • Works for me well, I was using Caffe on Ubuntu 15.04 and getting: "libcudnn.so.4: cannot open shared object file:No such file or directory" this fixed it , Thanks very much!
    – Ocxs
    May 6, 2016 at 14:11
  • I had the same probem in Debian 8.5. In my case, I installed cuda through the package nvidia-cuda-toolkit (it installs cuda 6.0), which does not install cuda in /usr/local. Command 'dpkg -L libcudart6.0' reports the library in /usr/lib/x86_64-linux-gnu/libcudart.so.6.0. Then I run 'sudo ldconfig /usr/lib/x86_64-linux-gnu' and it worked for me. Sep 2, 2016 at 10:01
13

First these that you need is to concatenate the paths to the CUDA binaries and libraries. This is simply done by adding the following lines to your .bashrc file.

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

If you are using a 32-bit operating system change lib64 to lib

Second, there should have been some shared object files installed in /usr/lib or /usr/lib64, depending on your operating system. These object files should be contained in a directory called "nvidia". The two files we are concerned with are names libcuda.so.drivernumber and libOpenCL.so.somenumber. To differentiate between the actual shared object files just use ls -l. The symbolic links will show what they are actually linking to.

As root, execute the following commands:

ln -s /usr/lib64/nvidia/libcuda.so.somenumber /usr/lib64/libcuda.so
ln -s /usr/lib64/nvidia/libOpenCL.so.somenumber /usr/lib64/libOpenCL.so

That should allow you to compile all the sources in the SDK.

As of Cuda 5.5 and Ubuntu 12.04/12.10, the command above becomes (notice the Ubuntu and Cuda directory changes) for 64bit

ln -s /usr/local/cuda/lib64/libcuda.so.5.5 /usr/lib/libcuda.so.5.5

That is, the lib folders on Ubuntu as of 12.04 are lib32 and lib; the 64 is implicit, and cuda 5.5 and greater now installs to a different directory.

3
  • ln: creating symbolic link `/usr/lib/libcuda.so': File exists
    – Alex
    May 30, 2012 at 4:23
  • the symbolic link isnt working for me. ln -s /usr/lib/nvidia/libcuda.so.295.41 /usr/lib/libcuda.so ln -s /usr/lib/nvidia/libOpenCL.so.1.0.0 /usr/lib/libOpenCL.so
    – Alex
    May 30, 2012 at 4:39
  • @Alex Can you figure out if /usr/lib/libcuda.so is a symbolic link and what it's linking to. If it's linking o the right place, then just try to create a symbolic link to the OpenCL shared object file, if it doesn't exist already.
    – sj755
    May 30, 2012 at 4:46
6

1 error while loading shared libraries: libcudart.so.6.0: cannot open shared object file: No such file or directory

  32-bit: sudo ldconfig /usr/local/cuda/lib

  64-bit: sudo ldconfig /usr/local/cuda/lib64

(refer: http://blog.csdn.net/shenchong721/article/details/21529295)

Works for me!

1
  • 1
    I get this error $ sudo ldconfig /usr/local/cuda-7.5/lib64 /sbin/ldconfig.real: /usr/local/cuda-7.5/lib64/libcudnn.so.4 is not a symbolic link
    – Mona Jalal
    Aug 31, 2016 at 22:45
5

LD_LIBRARY_PATH is strongly deprecated. It may mess up other programs, and others may reset it. It should only be used to temporarily override the permanent paths for testing purposes (don't take my word, google it).

Instead, add a line with your cuda lib directory on it to /etc/ld.so.conf, after any existing lines.

For example, if you installed on /usr/local/cuda, you will need to add

32-bit : /usr/local/cuda/lib

64-bit : /usr/local/cuda/lib64

Save, and run ldconfig. This should permanently fix the problem.

The symbolic links are probably already set up by the installation. If not, then add them as Alex advised.

Note - I received errors referencing /lib, but I needed to add lib64 to fix them.

2

create a nvidia_settings.conf file in /etc/ld.so.conf.d/ and add the path to the libs in the file nvidia_settings.conf

 /usr/local/cuda/lib64
 /usr/local/cuda/lib

Now to update the changes run the following command:

sudo ldconfig
1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib

or if you are running cuda-5.0 on a 64-bit machine

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.0/lib64
0

the system find library with ld tool. as the top answer says, 64-bit: sudo ldconfig /usr/local/cuda-xx/lib64 ;;xx is the cuda libraryedition

0

In my case I was running an application using MPI. The error was:

libcudart.so.7: cannot open shared object file

CUDA was properly installed in all nodes. Also, as in the previous answers, the variables $PATH and $LD_LIBRARY_PATH were pointing to the binary and libraries respectively.

Passing the $PATH and $LD_LIBRARY_PATH in the MPI command solved the issue.

mpirun -x PATH=$PATH -x LD_LIBRARY_PATH=$LD_LIBRARY_PATH ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.