Linkage of from CUDA_TOOLKIT_ROOT_DIR/lib64

I’m building a library that depends on CUDA & cuBLAS.
A peculiarity I’m seeing is that the paths are resolved for the CUDA
& cuBLAS libraries

--> ldd (0x00007ffda4173000) => /usr/lib/x86_64-linux-gnu/ (0x00007f5360f88000) => /gpfs/fs1/SHARE/Utils/CUDA/ (0x00007f535ccd2000) => /lib/x86_64-linux-gnu/ (0x00007f535c8e1000) => /lib/x86_64-linux-gnu/ (0x00007f535c543000) => /lib/x86_64-linux-gnu/ (0x00007f535c33f000) => /lib/x86_64-linux-gnu/ (0x00007f535c120000) => /lib/x86_64-linux-gnu/ (0x00007f535bf18000) => not found => /usr/lib/x86_64-linux-gnu/ (0x00007f535bb8f000) => /lib/x86_64-linux-gnu/ (0x00007f535b977000)
/lib64/ (0x00007f5362373000)

while the path for is not.
Explicitly setting the $LD_LIBRARY_PATH takes care of this
at runtime, but I would prefer to have the path already set so the
user doesn’t have to figure this out.
These are the rules that I’m using in my CMakeLists.txt file

find_package(CUDA QUIET REQUIRED) # Keep this form for backward-compatibility with older CMake.
# Dummy library for builds on non-GPU nodes.
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --std=c++11")
target_link_libraries(CUDA-SGEMM cuda cublas **cublasLt**)

which I put together by trial-and-error. I’m using cmake
I would hope there’s just some simple setting I need to use – maybe
I’m over-specifying in the above rules – but I haven’t found any
info on this by googling-around on the web.
I get the impression that cmake has some mechanisms
already in place for handling CUDA & cuBLAS but hadn’t been
built to handle cublasLt.

I had originally posted this as a “Usage” issue but it looks like “code” is more correct.
I’m sorry about spamming everyone with duplicate messages, I’m new to this forum.

If you run readelf -a | grep -i path what are RUNPATH that are being stored? In addition what path are you adding to LD_LIBRARY_PATH?

The readelf gives me this

 0x000000000000001d (RUNPATH)   Library runpath: [/gpfs/fs1/SHARE/Utils/CUDA/]

which corresponds to the arguments I’d used here


and the first directory contains the library and its links

 /gpfs/fs1/SHARE/Utils/CUDA/ ->
 /gpfs/fs1/SHARE/Utils/CUDA/ ->

If I put this same path on the $LD_LIBRARY_PATH then I get correct resolution => /gpfs/fs1/SHARE/Utils/CUDA/ => /gpfs/fs1/SHARE/Utils/CUDA/ (0x00007fb99e495000)

What puzzles me is why I have to do this for but not, which is already linked correctly without setting $LD_LIBRARY_PATH

Okay I am pretty sure I understand why this is failing.

RUNPATH on an executable is only used for finding direct dependencies and not indirect. In this case cublasLt is being treated as an indirect dependency ( cublas depends on it, but has no relevant RUNPATH values ).

So why is cublasLt an indirect dependency, while you are explicitly requesting it on the link line? Well the linker by default is now dropping unneeded libraries final since you are not directly calling any symbols that are inside of it ( or they are all weak symbols ).

The quickest solution is to add the following to your CMakeLists.txt to disable this linking behavior:

target_link_options(CUDA-SGEMM PRIVATE "LINKER:--no-as-needed")

The longer term solution is to work with cublas team to have them setup the proper RUNPATH values for loading of cublasLt to work no matter where it is installed.

This didn’t seem to help. Does the flag need to be applied some other way?
I see the flag being passed through in the file



/usr/bin/c++ -fPIC  -Wl,--no-as-needed -shared -Wl,-soname, -o CMakeFiles/CUDA-SGEMM.dir/CUDADriver.c.o   -L/gpfs/fs1/SHARE/Utils/CUDA/  -L/gpfs/fs1/SHARE/Utils/CUDA/  -Wl,-rpath,/gpfs/fs1/SHARE/Utils/CUDA/ /gpfs/fs1/SHARE/Utils/CUDA/ -lpthread -ldl /usr/lib/x86_64-linux-gnu/ -lcuda -lcublas 

But it doesn’t show up in the logs, I see the --as-needed being used instead, in


Ok this seemed to do it:

target_link_options(CUDA-SGEMM PRIVATE "LINKER:--no-as-needed")
target_link_options(CUDA-SGEMM PRIVATE "LINKER:-lcublasLt")

I’m going to go ahead and close this one. Thanks for the help!!