dyld: Library not loaded: @rpath/libcudart.dylib ?

What am I doing wrong?

RCS-Mac-Pro:~ rmark$
cd /Applications/CUDA/CUDA_Nvidia_GPU_Benches/Mandelbrot_
RCS-Mac-Pro:Mandelbrot_ rmark$ ls -l
total 69096
-rwxr-xr-x 1 rmark staff 758500 Sep 14 08:45 Mandelbrot
drwxrwxr-x 7 rmark staff 238 Sep 19 20:05 data
-rw-rw-r-- 1 rmark staff 222040 Sep 9 02:34 libGLEW.1.5.0.dylib
-rw-rw-r-- 1 rmark staff 222040 Sep 9 02:34 libGLEW.1.5.dylib
-rw-rw-r-- 1 rmark staff 222040 Sep 9 02:34 libGLEW.dylib
-rwxrwxr-x 1 rmark staff 15913168 Sep 3 10:00 libcublas.dylib
-rwxrwxr-x 1 rmark staff 5444172 Sep 3 10:00 libcublasemu.dylib
-rwxrwxr-x 1 rmark staff 276652 Sep 3 10:00 libcudart.dylib
-rwxrwxr-x 1 rmark staff 8481764 Sep 3 10:00 libcufft.dylib
-rwxrwxr-x 1 rmark staff 1501720 Sep 3 10:00 libcufftemu.dylib
-rw-rw-r-- 1 rmark staff 2197668 Sep 9 02:34 libnvcuvid.dylib
-rwxrwxr-x 1 rmark staff 13100 Sep 3 10:00 libtlshook.dylib
-rw-r–r-- 1 rmark staff 88094 Sep 14 08:52
mandelbrot_NV9600GT.jpg
-rw-rw-r-- 1 rmark staff 47 Sep 9 02:34 params.txt
RCS-Mac-Pro:Mandelbrot_ rmark
$ /Applications/CUDA/CUDA_Nvidia_GPU_Benches/Mandelbrot_/Mandelbrot
dyld: Library not loaded: @rpath/libcudart.dylib
Referenced
from: /Applications/CUDA/CUDA_Nvidia_GPU_Benches/Mandelbrot_/Mandelbrot
Reason: image not found
Trace/BPT trap

you’re not doing wrong but it seems like you didn’t set properly environment variables to your library path

open a terminal

export LD_LIBRARY_PATH=your_full_path_to_the_library

should then work properly

regards

I wish NVidia would use the “-install_name” linker option when they build their dylibs. Then this would be a non-issue.

Most Mac apps and libraries assume that users do not know how to play with DYLD_LIBRARY_PATH environment variable. The “-install_name” linker option sets a default value for the library search path, so the user does not have to diddle with these Environment variables. Unfortunately NVidia does not set this when they build their dynamic libraries.

Here is what they need to add to their makefile:
-install_name “/usr/local/cuda/lib/libcudart.dylib”

See the [topic=“155824”]Makefile templage for Cocoa/CUDA projects[/topic] for showing how to set this option. That example shows how to set it for a new dyllib that is shipped inside of a new application’s bundle.

Does it work for you now rmark? I’m having the same problem even though I’ve added the environment variables. It looks like this:

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

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH

Im compiling a Matlab mex file using the following commands in Matlab console:

!nvcc -c knn.cu -Xcompiler -fPIC -I/Applications/MATLAB_R2009b.app/extern/include/

nvmex knn.o -L/usr/local/cuda/lib -lcudart -lcufft -cxx -lcuda

It’s compiling alright but recieve the following error when running the program:

??? Invalid MEX-file '/Users/Snut/CUDA/v2/knn.mexmaci':

dlopen(/Users/Snut/CUDA/v2/knn.mexmaci, 1): Library not loaded: @rpath/libcudart.dylib

  Referenced from: /Users/Snut/CUDA/v2/knn.mexmaci

  Reason: image not found.

What’s up with that?

Edit: typo

Nvidia is actually doing something much better than using -install_name now by using @rpath/libcudart.dylib .

To take advantage of this all you need to do is use -Xlinker -rpath,/usr/local/cuda/lib as an argument to nvcc during the build. This will bake a runtime library search path into the compiled binary such that user’s who don’t (or can’t due to stability reasons) define DYLD_LIBRARY_PATH will be covered.

I know this is an old thread, but in case anyone comes across the same problem as Kaspar (and I) had, the solution is to pass the argument

LDFLAGS='\$LDFLAGS -Wl,-rpath,/usr/local/cuda/lib'

to mex (ie. it’s not enough to pass -Xlinker -rpath,/usr/local/cuda/lib to nvcc). Apologies if this was obvious.

Thanks Bionary for the help.

Solved my problem. You are my hero, Thanks!