Library not loaded: @rpath/libcudart.dylib


I know this has been on the forums before but I’m growing ever desperate. Im hoping one of you can help me with this problem. I have a .cu file that I can compile perfectly well thanks to the following suggestion by mfatica in this thread by laxxy: Typing

nvcc -c -Xcompiler -fPIC -I /Applications/

in the terminal and then

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

in the matlab terminal compiles ‘knn.mexmaci’ successfully. However, running the app only returns “Library not loaded: @rpath/libcudart.dylib”. These lines are returned by printenv (minus uninteresting stuff),




As you can see, I’ve set the environment variables numerous times. So far, I’ve only come across posts where the problem is solved by setting the environment variables. Is there any other way to work around this?

It looks like you have not downloaded and installed the “CUDA Toolkit”. The driver download does not install that library.

do this: ls /usr/local/cuda/lib

See if libcudart.dylib is actually there.

Ok thanks, just did. I’m afraid it is there. What bothers me is that it wont run even though I can compile. For instance, compiling without -lcudart yields all the undefined symbol errors I would expect so the compiler correctly identifies libcudart.

Any chance of clarifying this?

Edit: Btw deviceQuery and bandwithTest pass successfully.


In case anyone else run into the same problem… Solution: Matlab has a seperate variable environment when executing mex functions. type “!export LD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PAT” ($LD_LIBRARY_PATH on Windows) in the Matlab command window or type “unix(‘otool -L foo.mex’)” to get dylib dependencies of your function and copy dylibs into either of the directories returned by “!echo $DYLD_LIBRARY_PATH”.