Basics: nvcc linker flags

Hi ,

We need to explicitly pass the liker flags during the compilation of cuda programs which use builtin cuda libraries like cuSparse, cuBLAS.

Can you please help understand ?

  • Why compilier cannot automatically detect the required linker files ? $PATH variable them already includes CUDA_PATH.
  • How to find out the list of supported linker arguments ?

Example cmd: nvcc -lcublas sgemm_tutorial.cu -o sgemm_tutorial
OS: Windows 10

Hi @sivakumaranandan,

Why compilier cannot automatically detect the required linker files ? $PATH variable them already includes CUDA_PATH.

No, it can’t. In principle, the compiler just compiles the code to objects, but wrapping the missing functions like placeholders (in reality they are pointers to functions). The linker is in charge of bringing parts of the library object to fulfil those missing functions pointed by the objects generated from your source code.

Another thing is that the library objects (linker files as you call them) are not searched in $PATH but in $LD_LIBRARY_PATH.

How to find out the list of supported linker arguments ?

Well, if you refer to the libraries such as -lcublas, it is pretty simple actually. You can go to the location of the library object (usually with the extension .so for shared objects) and have a look at the file names. They usually are like:

libcublas.so

From it, you replace lib by l and get rid of the extension.

That is at least for Linux. For Windows, they should be .lib or something like that.

Regards,
Leon

1 Like