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?

Breakthrough
  • 2,444
  • 2
  • 23
  • 37
Alex
  • 503
  • 2
  • 6
  • 14
  • How did you compile the code? – Adam27X May 30 '12 at 01: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 '12 at 01:43
  • Sounds like the lib was probably renamed, is there anything with "libcudard" in its name in the /usr/lib folder? –  May 30 '12 at 01: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 '12 at 02: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 '12 at 02:21
  • Are you getting this error when trying compile the code? or are you getting it at run-time? If you're getting it when compiling, please post the arguments you're sending to `g++`. If you're getting it at run-time, then I don't think this question belongs on SO. – Drew Chapin May 30 '12 at 02:30
  • @sj755 is found the file and added export PATH=$PATH:/usr/local/lib/:/usr/local/lib/openmpi:/usr/local/ cuda/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/ lib/openmpi/:/usr/local/cuda/lib/: – Alex May 30 '12 at 02:45
  • @Alex Alright, did you open a new terminal window and try recompiling and running? – sj755 May 30 '12 at 02:49
  • @sj755 i cant, it just enters the folder then back out, and i for some reason cant delete the files – Alex May 30 '12 at 03:03
  • @Alex I seem to have forgotten a few more details for compiling the SDK. I'll post up an answer. Also, you should start referring to folders as directories. Until CUDA 5 comes around, you're probably going to be running compilation commands from the terminal. – sj755 May 30 '12 at 03:12

8 Answers8

80

try:

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

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

cheers

andrewsi
  • 10,807
  • 132
  • 35
  • 51
Edgar
  • 801
  • 6
  • 3
  • 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 – Will Beauchamp Jul 19 '14 at 22:42
  • 1
    Is is related to `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64`? – SolessChong Oct 13 '14 at 17:52
  • When running this I get an error but it solves the problem nonetheless! Thanks! – Gu1234 Feb 28 '16 at 08: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 06 '16 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. – valerio_sperati Sep 02 '16 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.

Tommy
  • 12,588
  • 14
  • 59
  • 110
sj755
  • 3,944
  • 14
  • 59
  • 79
  • ln: creating symbolic link `/usr/lib/libcuda.so': File exists – Alex May 30 '12 at 04: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 '12 at 04: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 '12 at 04: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
    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 '16 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
surendran
  • 478
  • 1
  • 8
  • 19
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
rodms
  • 371
  • 3
  • 12
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

dzhwinter
  • 49
  • 1
  • 5
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 ...
user9869932
  • 6,571
  • 3
  • 55
  • 49